Skip to content

Fix WebSocket 1009 close: permit, bad frames, server close - #2427

Merged
hyperxpro merged 1 commit into
mainfrom
fix/ws-1009-close-followups
Dec 6, 2026
Merged

hyperxpro merged 1 commit into
mainfrom
fix/ws-1009-close-followups

Conversation

@hyperxpro

Copy link
Copy Markdown
Member

Motivation:

After a 1009, #2426 waits up to 10 seconds for the server to close, but releases the connection permit as soon as the close frame is sent. A server that never closes lets a reconnecting client go past maxConnections. Frames the decoder already holds are still parsed, so a bad frame behind the big message makes Netty send a second close frame and close the connection first. The server's own close frame is dropped, so the client waits the full 10 seconds and reports 1006.

Modification:

Keep the permit until the connection is closed. Replace the decoder after the 1009 with one that does not close on a protocol violation, and ignore decoder errors while waiting. Handle the server's close frame while waiting. Track the closing state with a channel attribute instead of scanning the pipeline for every frame.

Result:

maxConnections holds after a 1009, the client sends one close frame and leaves closing to the server, and a close frame from the server ends the wait with its code. A reconnect from onError with maxConnections set is now refused until the old connection closes.

@hyperxpro
hyperxpro merged commit 6277994 into main Dec 6, 2026
17 checks passed
@hyperxpro
hyperxpro deleted the fix/ws-1009-close-followups branch December 6, 2026 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant