← Back to Pull requests

fix(network): add the time the broker may hold a request to its timeout #559

Closed
unknown closed this pull request without merging on Dec 02, 2026 09:59 UTC
View on GitHub
unknown unknown commented on Dec 01, 2026 20:24 UTC
Author

Fixes #558

Fetch, ShareFetch and JoinGroup requests can be held by the broker before it answers: a fetch for up to maxWaitMs when there is no data, and a JoinGroup for up to the rebalance timeout. The connection timed them with the flat requestTimeout, so a requestTimeout below that wait timed them out and destroyed the socket.

  • The request builders of Fetch (v4 to v17), ShareFetch (v1 and v2) and JoinGroup (v0 to v9) set context.brokerWait on their writer, like Produce sets context.noResponse. JoinGroup v0 has no rebalance timeout, so it uses the session timeout.

  • The connection times a request with requestTimeout plus its brokerWait, capped at 2^31 - 1 ms. Node fires a timer after 1 ms when its delay is above that.

  • docs/base.md explains it under timeout vs requestTimeout.
  • One side effect: a JoinGroup to a coordinator that stops answering now takes up to requestTimeout plus the rebalance timeout to fail, since that is how long the broker may hold it.

    How I checked it, on a single broker:

    | Case | main | this PR |
    | ------------------------------------------------------------------- | -------------------------------------- | ------------------------------- |
    | Idle topic, requestTimeout: 3000, maxWaitTime: 5000 | stream errors at 15.0 s, 4 disconnects | alive after 25 s, 0 disconnects |
    | Join behind a killed member (60 s session), requestTimeout: 10000 | fails after 43.1 s | joins at 60.0 s, 0 disconnects |

    New tests:

  • Connection.send accepts a response that arrives after requestTimeout but within the broker wait. It times out at 500 ms on main.

  • A held request with no response still times out, at requestTimeout plus the broker wait (1.5 s here, 0.5 s on main).

  • A requestTimeout of 2^31 - 1 plus a broker wait does not time out after 1 ms.

  • A consumer reading an idle topic with requestTimeout: 1000 and maxWaitTime: 2000 has no errors or disconnects after 4.5 s, then gets a new message. Fails 3 of 3 on main, passes 3 of 3 here.

  • Each Fetch, ShareFetch and JoinGroup codec test checks brokerWait.
  • I couldn't run test/network/connection.test.ts as a whole locally, since its setup needs the SASL brokers, so the new test there ran on its own.

    Diff: 298 lines (+223 / -75) across 3 files Reviewer: ShogunPanda Review duration: 814m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 298 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    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
    Diff Size diff_size
    0.341
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #559"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 40% (MEDIUM) · Higher = larger blast radius
    40%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 15.8% · Safe to merge
    15.8%