← Back to Pull requests

fix(websocket): queue Close frame behind pending sends #6237

Open
unknown opened this pull request with 221 lines diff across 2 files
View on GitHub
unknown unknown commented on Nov 21, 2026 05:22 UTC
Author

Fixes #6236.

Problem

ws.send(blob) followed by ws.close() writes the Close frame before the Blob (and before anything queued after it). The close path in connection.js wrote the Close frame straight to the socket, bypassing the SendQueue that data frames go through, so it overtook any queued sends (a Blob send waits on blob.arrayBuffer()). A server that follows RFC 6455 stops reading once it has the Close frame, so those messages are silently lost while the client's close event 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.

  • The handler keeps a reference to the SendQueue created in #onConnectionEstablished.

  • closeWebSocketConnection uses 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) to test/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.

  • Full websocket suite (borp -p "test/websocket/*/.js"): 179 passed, 0 failed.

  • ESLint on the changed files: clean.

  • The WPT suite was not run locally; relying on CI for it.
  • ---

    AI assistance disclosure: this PR was prepared with the help of an AI coding assistant; the change was reviewed and tested locally before submission.

    Diff: 221 lines (+165 / -56) across 2 files Reviewer: mcollina Review duration: 2358m
    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
    0.37
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 36.8% (MEDIUM) · Higher = larger blast radius
    36.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 43.0% · Lower = rushed or shallow review
    43.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 21.0% · Safe to merge
    21.0%
    Repository