Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

If WebSocket closes abnormaly send status code 1006 to app#12900

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
mkurz wants to merge4 commits intoplayframework:main
base:main
Choose a base branch
Loading
frommkurz:websocket_status-code_1006

Conversation

mkurz
Copy link
Member

SeeWebSocket specs 7.4.1

1006 is a reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint. It is designated for use in applications expecting a status code to indicate that the connection was closed abnormally, e.g., without sending or receiving a Close control frame.

Also7.1.5

IfThe WebSocket Connection is Closed and no Close control frame was received by the endpoint (such as could occur if the underlying transport connection is lost),The WebSocket Connection Close Code is considered to be 1006.

And11.7

-+------------+-----------------+---------------+------------------------------------------------------------| | 1006       | Abnormal Closure| hybi@ietf.org | [RFC 6455](https://datatracker.ietf.org/doc/html/rfc6455)  |-+------------+-----------------+---------------+------------------------------------------------------------|

The problem is right now the app only gets a status code if the connection gets closed correctly, triggered by the client. (If user code triggers closing, no status code will be send to the app which is OK).

However, if a WebSocket connection is lost / abnormaly closed, for whatever reason (network is down, cable unplugged, ...), currently the app does not receive a close message, but according to the specs this is what 1006 is for.

Currently, one can only detect if a connection is closed via watchTermination on a flow like (java code):

Flow.fromSinkAndSource(someSink,someSource).watchTermination((prevMatValue,completionStage) -> {// This function will be run when the stream terminates// the CompletionStage provided as a second parameter indicates whether// the stream completed successfully or failedcompletionStage.whenComplete((done,exc) -> {if (done !=null) {// For Play WebSockets, we -->always<-- enter this if condition, even when the connection was closed abnormallySystem.out.println("The stream materialized successfully " +prevMatValue.toString());      }else {System.out.println(exc.getMessage());      }    });returnprevMatValue;});

As you see from this code, the watchtermination is always called in a way so that done is set, no matter what the reason is that a connections got closed: you can not determine the connection was closed cleanly (triggered by user code or by the client) or if the connection was closed abnormally. There is only one work around I can think of currently, which would be to capture the close status code of a close message, if one is received, and check in the watch termination if there was a close message before, and if so one knows if the connection was closed clean or not (also the user needs to save if the connection was closed by user code of course to make the distinction).

With this PR I always make the WebSocket send a close status code to the user code with status 1006 if the connection is not closed cleanly by user code nor by the client.

@mkurz
Copy link
MemberAuthor

I guess the close messages in that file are handled by the flow as if sent by user code - however they are not really sent by the user, so should we also pass 1006 to the app for connections that get closed triggered from that code?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
Status: 🆕 New
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

1 participant
@mkurz

[8]ページ先頭

©2009-2025 Movatter.jp