Skip to content

Comments

add a comment about websocket close test#6163

Open
anonrig wants to merge 1 commit intomainfrom
yagiz/fix-websocket-closed
Open

add a comment about websocket close test#6163
anonrig wants to merge 1 commit intomainfrom
yagiz/fix-websocket-closed

Conversation

@anonrig
Copy link
Member

@anonrig anonrig commented Feb 24, 2026

For web compliance... purposes...

@anonrig anonrig requested review from a team as code owners February 24, 2026 21:54
@anonrig anonrig requested review from dom96 and jasnell February 24, 2026 21:54
@anonrig anonrig force-pushed the yagiz/fix-websocket-closed branch from 18e1733 to 3a76249 Compare February 24, 2026 21:55
@anonrig anonrig force-pushed the yagiz/fix-websocket-closed branch from 3a76249 to 8c41e27 Compare February 24, 2026 21:57
@anonrig anonrig enabled auto-merge February 24, 2026 21:57
Copy link
Collaborator

@danlapid danlapid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jp4a50 is this what I think it is?

@anonrig anonrig disabled auto-merge February 24, 2026 21:58
@anonrig anonrig requested a review from jp4a50 February 24, 2026 21:58
@codspeed-hq
Copy link

codspeed-hq bot commented Feb 24, 2026

Merging this PR will degrade performance by 16.27%

❌ 1 regressed benchmark
✅ 69 untouched benchmarks
⏩ 129 skipped benchmarks1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
jsonResponse[Response] 40 µs 47.7 µs -16.27%

Comparing yagiz/fix-websocket-closed (f5ce26a) with main (5080c86)

Open in CodSpeed

Footnotes

  1. 129 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@anonrig anonrig force-pushed the yagiz/fix-websocket-closed branch from 8c41e27 to 2535de8 Compare February 24, 2026 22:17
// fires for a server-initiated close. Queue a proper close reply frame through the
// outgoing message pump so that a reciprocal Close frame is actually sent on the
// wire, then mark outgoing as closed.
auto pendingAutoResponses = autoResponseStatus.pendingAutoResponseDeque.size() -
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like the wrong layer to solve this

@anonrig anonrig changed the title fire close event for server-initiated close on websockets add a comment about websocket close test Feb 24, 2026
@kentonv
Copy link
Member

kentonv commented Feb 24, 2026

We intentionally don't send close messages automatically in reply to receiving a close because it breaks proxying. Imagine a worker which has two WebSocket connections open, A and B, and is proxying between them (forwarding all messages received on A to B and vice versa).

Now the worker receives a close message on A. It forwards the close message to B. It then needs to wait for B's reply close message, so it can then forward that to A.

If the system automatically sends a close reply to A immediately upon receiving a close message, this doesn't work right. This is why we didn't implement it that way.

With that said, you could make some valid arguments that we made the wrong choice here. Is it actually important that B get a chance to flush remaining messages and provide its own close message? Given that the WebSocket spec says that the reply close should happen automatically, perhaps it's the case that WebSocket close messages are not intended to be graceful, but rather intended to immediately terminate the connection. This isn't really "good networking theory" but maybe it's fine in practice and not worth it to deviate?

Maybe what we should really do is provide an explicit extension that lets people specify when they want to manually manage close messages? Like an allowHalfOpen sort of thing?

I could be convinced.

@anonrig anonrig force-pushed the yagiz/fix-websocket-closed branch from 7ee846c to f5ce26a Compare February 24, 2026 22:32
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.

4 participants