Handle websocket close events differently #5024
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Right now today when we "disconnect" a websocket we simply use stop reply and let cowboy handle the rest, where as cowboy has a reply shutdown that allows you to send the status code and a message.
I chose 3000 as it is currently registered with the iana as "unauthorized" the entire 3000-3999 status code space is left open for libraries and frameworks to register. We could claim 3001 for "kicked" or something for example.
This solves #4924 as we can simply check for error code 3000 in the ws onConnClose case.
The second issue is that when a user navigates away from the page SOME browsers will initate a websocket close event with status 1001 (going away) and isTrusted set to true. This was causing the connection status flash in liveview to flicker if you navigated away using a standard a tag href.
Work left to do: