Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebSockets Next: CloseReason - fix NPE if connection terminated abruptly #42282

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to return internal server error in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it's kind of an internal server error. Also I did not find a better code in the list defined by the spec: https://datatracker.ietf.org/doc/html/rfc6455#section-7.4.1. There is 1006 but it's reserved and has a special meaning.

}
return new CloseReason(code, ws.closeReason());
}
return null;
}
Expand Down