Refuse connections once the server starts closing, so its close cannot hang #160
No reviewers
Labels
No labels
area:docs
area:identity
area:ops
area:plugin
area:server
channel:community
channel:direct
channel:owned
channel:press
channel:social
e2ee-constrained
gate:at-ga
gate:pre-ga
marketing
parity
relay:absent
relay:planned
relay:requested
relay:supported
risk:additive
risk:contract
risk:none
usability
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Nectenda/nectenda!160
Loading…
Reference in a new issue
No description provided.
Delete branch "worktree-nec-89-destroy-race"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Task: NEC-89
NEC-89's e2e hang was the test server's
close(), not Obsidian. The close codes added in #157 showed it in soak run 710, which caught the hang twice in 40 iterations. The early disconnect was the server's own shutdown, code 1001 "server restarting", so the test was stuck inawait server.close().How it hung
WsServer.destroy()closes the sockets it has, then waits up to 2 s for each close to be acknowledged.clear()then dropped it without ever closing it.http.close()waits for every connection to end, so it waited on that socket until vitest's 300 s timeout.The fix.
destroy()now marks the server as closing before it touches a socket.destroy()'s own code.Production impact. Small. Production closes the HTTP server before closing sockets and exits after a 10 s drain, so at worst a late socket slowed a deploy's shutdown.
Tests.
shutdown-race.test.tsmakes the race deterministic by pausing the first client's socket, sodestroy()is still waiting when the second client connects.Still to prove. An 80-iteration soak dispatched on this branch. The current rate is about 1 hang in 20 iterations, so 0 hangs in 80 would be about 1.6% likely if nothing had changed.
Changelog
NONE
🤖 Generated with Claude Code
https://claude.ai/code/session_01Q6gkmHZ3pYvsZCCpiA9qe9
1370c2d966151bfc729b