Skip to content

Commit

Permalink
WebSockets Next: CloseReason - fix NPE if connection terminated abruptly
Browse files Browse the repository at this point in the history
- fix invocation of OnClose callback with a CloseReason param
- resolves quarkusio#42271
  • Loading branch information
mkouba committed Aug 2, 2024
1 parent 346a834 commit 983b8bf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,9 @@ public String getMessage() {
return message;
}

@Override
public String toString() {
return "CloseReason [code=" + code + ", " + (message != null ? "message=" + message : "") + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,12 @@ public BroadcastSender broadcast() {
public CloseReason closeReason() {
WebSocketBase ws = webSocket();
if (ws.isClosed()) {
return new CloseReason(ws.closeStatusCode(), ws.closeReason());
Short code = ws.closeStatusCode();
if (code == null) {
// This could happen if the connection is terminated abruptly
return CloseReason.INTERNAL_SERVER_ERROR;
}
return new CloseReason(code, ws.closeReason());
}
return null;
}
Expand Down

0 comments on commit 983b8bf

Please sign in to comment.