Repository navigation
fix(server): don't close the handle twice after a failed handshake - #322
Draft
lucidstack wants to merge 1 commit into
Draft
lucidstack wants to merge 1 commit into
lucidstack wants to merge 1 commit into
Conversation
A client that hangs up as soon as it reads the 400, like a local port scanner probing for web servers, has its handle closed by the EOF teardown before the scheduled close runs, which then raises "handle … is already closing".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Guard the scheduled
tcp_handle:close()after a failed handshake withis_closing(), likeclose_clientandtcp.lua's_remove_clientalready do, and add a spec for both orderings.Why
I kept seeing this a few seconds after the server came up:
The culprit was a local dev-server discovery daemon sending
GET /to every new loopback port. The WARN is fair enough — it isn't a WebSocket upgrade — but the error isn't: the daemon hangs up as soon as it reads the 400, so the EOF teardown intcp.luacloses the handle before the scheduled close runs, and that one then raises 😅Any client that hangs up straight after the response reproduces it (
PORTfrom:ClaudeCodeStatus):python3 -c 'import socket; s = socket.create_connection(("127.0.0.1", PORT)); s.sendall(b"GET / HTTP/1.1\r\nHost: x\r\n\r\n"); s.recv(200); s.close()'curldidn't trigger it for me, as it hangs up a little later.. so it's a race, and fast clients win it.