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

[2.8.x] Log websocket communication problems + handle special Netty case #11519

Merged

Conversation

mkurz
Copy link
Member

@mkurz mkurz commented Oct 27, 2022

(I am looking into this because a premium sponsor asked me because they run into problem regarding websockets.)

When a client closes a websocket connection, it's possible it sends an optional status code. Those status codes are defined here: https://www.rfc-editor.org/rfc/rfc6455#section-7.4

Now, if a client sends a status code not defined in that list (or one that is reserved for other purposes) akka-http does not care but let's the close status code pass through into the application code, so it does not distinguish between valid and invalid status codes.

Netty however is very strict, it does not pass a play.api.http.websocket.CloseMessage on into application code. As a consequence an app handling CloseMessage will never receive it, even though Netty closes the connection and actually throws an error. However, right now that error is swallowed by Play, it's impossible to see what's going on. So this pull requests adds a warning if a problem occurs. That at least gives developers a indication that something wrong happened.

Update: In the second commit of this PR i decided to not just log a warning, but to also handle the Netty close status code problem explicitly by passing the CloseMessage with the "invalid" Status code down to the app. I think this makes a lot of sense, devs should be able to react even on invalid status codes, like they can for akka-http. It's a bit tricky right now since the information is only available in the error message. However even if Netty changes that string, at least the code would fall back and log the warning, so it's at least visible somehwere:

2022-10-28 00:15:02 WARN  p.c.s.common.WebSocketFlowHandler  WebSocket communication problem: Invalid close frame getStatus code: 1201

@mkurz mkurz added this to the 2.8.19 milestone Oct 27, 2022
@mkurz mkurz force-pushed the log_websocket_communication_problems branch from 247221f to 9d512c7 Compare October 28, 2022 09:00
@mkurz mkurz changed the title Log websocket communication problems + handle special Netty case [2.8.x] Log websocket communication problems + handle special Netty case Oct 28, 2022
@mkurz mkurz force-pushed the log_websocket_communication_problems branch from 44151bb to cbe8476 Compare November 1, 2022 08:14
@mkurz mkurz force-pushed the log_websocket_communication_problems branch from cbe8476 to 8b6a420 Compare November 1, 2022 12:22
@mkurz mkurz force-pushed the log_websocket_communication_problems branch from 957fbef to f81bdf2 Compare November 7, 2022 19:53
@mergify mergify bot merged commit 3754387 into playframework:2.8.x Nov 7, 2022
@mkurz mkurz deleted the log_websocket_communication_problems branch November 7, 2022 20:30
@mkurz
Copy link
Member Author

mkurz commented May 9, 2023

main: #11520

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants