Skip to content

Commit

Permalink
fix: Fix failure when Vite sends many messages in sequence
Browse files Browse the repository at this point in the history
Sending multiple messages at the same time resulted in

java.lang.IllegalStateException: The remote endpoint was in state [TEXT_FULL_WRITING] which is an invalid state for called method

which originates in calling `browserSession.getAsyncRemote().sendText` a second time before the complete callback for the first call has been called.

Now the getBasicRemote() method is used instead which blocks until the message has been sent.
  • Loading branch information
Artur- committed May 8, 2024
1 parent d55d933 commit e5bfc5f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,10 @@ public void close() throws InterruptedException, ExecutionException {
.sendClose(CloseCodes.NORMAL_CLOSURE.getCode(), "");
closeRequest.get();
}

@Override
public void onError(WebSocket webSocket, Throwable error) {
getLogger().error("Error from Vite websocket connection", error);
Listener.super.onError(webSocket, error);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,14 @@ public class ViteWebsocketProxy implements MessageHandler.Whole<String> {
public ViteWebsocketProxy(Session browserSession, Integer vitePort,
String vitePath) throws InterruptedException, ExecutionException {
viteConnection = new ViteWebsocketConnection(vitePort, vitePath,
browserSession.getNegotiatedSubprotocol(),
msg -> browserSession.getAsyncRemote().sendText(msg, result -> {
if (result.isOK()) {
getLogger().debug("Message sent to browser: {}", msg);
} else {
browserSession.getNegotiatedSubprotocol(), msg -> {
try {
browserSession.getBasicRemote().sendText(msg);
} catch (IOException e) {
getLogger().debug("Error sending message to browser",
result.getException());
e);
}
}), () -> {
}, () -> {
try {
browserSession.close();
} catch (IOException e) {
Expand Down

0 comments on commit e5bfc5f

Please sign in to comment.