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 should use close code 1006 when the connection is closed abnormally #182

Open
catgirlinspace opened this issue Apr 16, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@catgirlinspace
Copy link
Contributor

catgirlinspace commented Apr 16, 2024

Currently when a WebSocket connection is closed abnormally closeCode remains nil, meaning hacks like this are required to know when it actually closed.

local isSocketClosed = false
task.defer(function()
	pcall(function()
		while websocket.next() do end
	end)
	isSocketClosed = true
end)

RFC 6455 says the code 1006 should be used for this: https://www.rfc-editor.org/rfc/rfc6455.html#:~:text=If%20_The%20WebSocket%0A%20%20%20Connection%20is%20Closed_%20and%20no%20Close%20control%20frame%20was%20received%20by%20the%0A%20%20%20endpoint%20(such%20as%20could%20occur%20if%20the%20underlying%20transport%20connection%0A%20%20%20is%20lost)%2C%20_The%20WebSocket%20Connection%20Close%20Code_%20is%20considered%20to%20be%0A%20%20%201006.

@filiptibell filiptibell added the bug Something isn't working label Apr 16, 2024
@filiptibell
Copy link
Collaborator

Turns out this one is a bit tricky to solve.
We're going to have to start inspecting all received web socket messages in the background and then forward them to websocket.next() when called, since stuff like while not websocket.closeCode do needs to work properly, and we can only know if the web socket has been closed by trying to receive on it.

I can do this soon, it's not too complicated, just a bit more work than initially expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants