fix(websocket): queue Close frame behind pending sends #6237
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.37) × (1 − Review Confidence (0.43)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.37 · 221 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Shallow Review Depth
shallow_review_depth
0.344
Diff Size
diff_size
0.323
Real PR Conversation Timeline
1 comments
"Review active on #6237"
general
weight: 0.35
mcollina
Fixes #6236.
Problem
ws.send(blob)followed byws.close()writes the Close frame before the Blob (and before anything queued after it). The close path inconnection.jswrote the Close frame straight to the socket, bypassing theSendQueuethat data frames go through, so it overtook any queued sends (a Blob send waits onblob.arrayBuffer()). A server that follows RFC 6455 stops reading once it has the Close frame, so those messages are silently lost while the client'scloseevent reports code 1000,wasClean: true.Fix
Queue the Close frame behind pending sends instead of writing it directly:
SendQueue.addFrame(frame, cb)enqueues an already serialized frame behind any pending sends.SendQueuecreated in#onConnectionEstablished.closeWebSocketConnectionuses the queue when one exists, falling back to the direct socket write otherwise.Only the client-initiated close path changes; the receiver's Close-frame reply is untouched.
Tests
Added
Close frame is queued behind pending blob sends (#6236)totest/websocket/close.js:send(new Blob(...)),send('after'),close(1000)from an open connection, asserting the server receives both messages before the close handshake completes. The test fails without the fix (Close overtakes the queue, both messages are lost) and passes with it.node --test test/websocket/close.js: 8 passed.borp -p "test/websocket/*/.js"): 179 passed, 0 failed.---
AI assistance disclosure: this PR was prepared with the help of an AI coding assistant; the change was reviewed and tested locally before submission.