Repository navigation
Conversation
|
Review requested:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #66676 +/- ##
==========================================
+ Coverage 90.69% 90.72% +0.02%
==========================================
Files 797 801 +4
Lines 278883 280738 +1855
Branches 53632 54182 +550
==========================================
+ Hits 252940 254698 +1758
+ Misses 16304 16207 -97
- Partials 9639 9833 +194
🚀 New features to boost your workflow:
|
|
@copilot resolve the merge conflicts on this branch. |
|
|
||
| // Switching protocols while an earlier response is still pending would | ||
| // allow the upgrade response to be written out of order. | ||
| if (socket._httpMessage || state.outgoing.length > 0) { |
There was a problem hiding this comment.
_httpMessage is unset until finish, but that fires async, not immediately. It doesn't actually get unset until a tick after the write call.
If the event loop blocks around the same time (event loop or just heavy GC) then finish can fire quite a long time after the response has been sent to the client. If it blocks longer than RTT (especially for localhost/LAN) then you can get a new request received in the meantime, and in that case it's possible for this to fire and kill connections in normal scenarios, where there's no pipelining present at all.
In practice I think that means a very busy server + low RTT to the client, so quite niche, but in that case you'd hit spurious upgrade connection failures at random, without any weird pipelining involved, which sounds very annoying for everybody.
You can check socket._httpMessage?.finished === false safely instead I think. That's set to true synchronously on end(), so it does exactly the same thing with no race involved:
| if (socket._httpMessage || state.outgoing.length > 0) { | |
| if (socket._httpMessage?.finished === false || state.outgoing.length > 0) { |
Destroy the connection instead of emitting the upgrade or connect event when an earlier response is still pending. This prevents protocol-switch responses from being written ahead of earlier HTTP responses. A response that has ended but has not emitted 'finish' yet is already queued on the socket, so it does not block the switch. When its 'finish' fires after the switch, the keep-alive timeout is not armed on the switched socket. Document the behavior and cover both methods with regression tests. Assisted-by: Codex Signed-off-by: Matteo Collina <hello@matteocollina.com>
dac57a0 to
1d9ce1d
Compare
Destroy the connection instead of emitting the upgrade or connect event when an earlier response is still pending. This prevents protocol-switch responses from being written ahead of earlier HTTP responses.
Document the behavior and cover both methods with regression tests.
—
AI gen, reviewed by me.