Skip to content

Commit

Permalink
fix(language-web): try to avoid leaking websockets
Browse files Browse the repository at this point in the history
  • Loading branch information
kris7t committed Jan 15, 2025
1 parent 4e3957d commit a4bd03d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ public void onSubscribeToPrecomputationEvents(String resourceId, PushWebDocument
/**
* Get the injector to satisfy the request in the {@code serviceContext}.
*
*
* @param context the Xtext service context of the request
* @return the injector for the Xtext language in the request
* @throws UnknownLanguageException if the Xtext language cannot be determined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public void onClose(int statusCode, String reason) {
LOG.warn("{} closed connection with status code {}: {}", webSocketSession.getRemoteSocketAddress(),
statusCode, reason);
}
if (!webSocketSession.isOpen()) {
webSocketSession.close();
}
webSocketSession = null;
}

Expand All @@ -91,10 +94,10 @@ public void onError(Throwable error) {
switch (error) {
case WebSocketTimeoutException ignored -> LOG.warn("Websocket connection timed out", error);
case EofException ignored -> LOG.warn("Websocket connection already closed", error);
default ->
LOG.error("Internal websocket error in connection from " + webSocketSession.getRemoteSocketAddress(),
error);
default -> LOG.error("Internal websocket error in connection from " + webSocketSession.getRemoteSocketAddress(),
error);
}
webSocketSession.close();
}

@OnWebSocketMessage
Expand Down Expand Up @@ -148,5 +151,6 @@ public void writeFailed(Throwable x) {
return;
}
LOG.warn("Cannot complete async write to websocket " + webSocketSession.getRemoteSocketAddress(), x);
webSocketSession.close();
}
}

0 comments on commit a4bd03d

Please sign in to comment.