Skip to content

DO NOT MERGE without coordinator GO: 3.x.x: drop an idle node connection after 20 s, below qbitd's 30 s idle close (#759) - #760

Merged
RobertClarke merged 2 commits into
3.x.xfrom
RobertClarke/759-rpc-pool-idle-bound
Oct 9, 2026
Merged

RobertClarke merged 2 commits into
3.x.xfrom
RobertClarke/759-rpc-pool-idle-bound

Conversation

@RobertClarke

@RobertClarke RobertClarke commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Part of #759. Product code (the frontends' node RPC client): DO NOT MERGE without the coordinator's GO.

The problem

The frontends' qbitd RPC client (rpc.rs) kept an idle keep-alive connection for 60 s. qbitd closes one after its -rpcservertimeout, 30 s by default.

  • A request written into a connection just as qbitd closes it is never read. It fails after the connection existed, so the error is the plain qbit RPC <method> transport failed, and nothing retries it.
  • A production deployment logs that error from the CTV broadcaster on about 1 pass in 8 on one frontend and 1 in 15 on the other. That fits this race: the broadcaster's 30 s tick runs in step with the 2 s refresh tick, so a second pooled connection idles right at about 30 s.
  • On submitblock, classify_offer records that failure as OfferOutcome::Unknown, and an unknown offer is never offered again. The race is rare at random block times, but each hit costs a block.

The change

  • rpc.rs: POOL_IDLE_TIMEOUT = 20 s, below QBITD_DEFAULT_RPCSERVERTIMEOUT (30 s); a const assert keeps it there. Rpc::new uses it.
    • Rpc::with_pool_idle_timeout sets another bound: for a node configured with a shorter idle close, and for tests.
    • node_client_builder() carries the bound. Every node client starts from it: Rpc's, the public API's and the load harness's.
  • api.rs: the public API's node client takes the bound. It took reqwest's 90 s default.
  • Load harness: the fault relay's upstream client and the harness's qbitd client take the bound, so a stale connection can't fail a forwarded call that no fault plan asked for.
  • docs/prism-rust-migration.md: keep qbitd's -rpcservertimeout, and any proxy's idle timeout in front of the node, above 20 s. The default 30 s is fine, and a raised value, such as 120, is fine too.

Relay calls stay on the bounded pool, deliberately. The first head sent each RELAY_METHODS call on a new connection. Review found the cost: the connect then sits inside submitblock's 1 s deadline (PRISM_BLOCK_SUBMIT_RPC_TIMEOUT_SECONDS).

  • A deadline that passes while connecting is a timeout, not a connect error, so it isn't RpcNotSentError.
  • A lost SYN (Linux retransmits after 1 s) or a slow accept would therefore record a block that never reached the node as unknown.
  • A warm pooled connection within the bound avoids both, so relays share the pool, as they did before this PR.

Not in this PR (left open on #759):

  • A retry for read-only methods after a non-connect transport failure. The bound removes the race, and a retry would be a separate policy change.
  • A configurable bound, such as an environment variable. Today a node or proxy that closes idle connections sooner than 20 s needs Rpc::with_pool_idle_timeout.
  • The integration fixtures' own node clients still use reqwest's default 90 s pool: live_pg_failover's node gate, live_regtest's fixture client and live_session_load's block watcher. They're test-only, so a follow-up moves them to node_client_builder() rather than restarting this PR's CI.
  • Pre-existing, seen in review: when no warm connection is free, submitblock connects within its 1 s deadline. A deadline that passes during that connect is recorded as unknown, not unsent. A connect deadline below the call's deadline, or a check that the connection never opened, would keep that case provably unsent.

Tests

tests/rpc_idle_close.rs runs the real client against a loopback node, which counts the connections it accepts. The node answers a request on a reused connection only within its idle limit (400 ms); a later one is read and dropped unanswered, as in the race.

  • a_call_after_the_nodes_idle_close_uses_a_new_connection: with a 200 ms bound and a 700 ms pause, the second call opens a second connection and gets its answer.
  • a_connection_kept_past_the_nodes_idle_close_fails_the_call: with the old 60 s bound, the second call reuses the stale connection (one connection in all) and fails with qbit RPC getblockcount transport failed. It is not RpcNotSentError. This proves the mock reproduces the production failure, and that the bound is what prevents it.

Local results at this head (65d26922):

  • cargo fmt --check and cargo clippy --locked --workspace --all-targets -- -D warnings are clean.
  • cargo test --locked -p qbit-prism-server -p qbit-prism-load: 113 test binaries, 0 failures. The PostgreSQL-gated tests skipped locally (no database), so CI's PostgreSQL shards are their run.
  • rpc_idle_close repeated 40 times at the first head: 40 of 40 green. Both remaining cases are unchanged since then.

🤖 Generated with Claude Code

…le close, and send each relay call on a new connection (#759)

The frontends' qbitd RPC client kept an idle keep-alive connection for 60
seconds, while qbitd closes one after its -rpcservertimeout, 30 seconds by
default. A request written into a connection just as the node closes it is
never read, and fails after the connection existed. That is the plain
"transport failed" error, which nothing retries. On submitblock it is an
unknown outcome, and the block is never offered again. A production
deployment logs that error from the CTV broadcaster on about one pass in
eight to fifteen, which fits this race: the broadcaster's 30 second interval
runs in step with the 2 second refresh interval.

The client now keeps an idle connection for at most 20 seconds
(POOL_IDLE_TIMEOUT), so it drops one before the node can close it. A
compile-time assert keeps the bound below QBITD_DEFAULT_RPCSERVERTIMEOUT.
node_client_builder() carries the bound, and the public API's node client
and the load harness's node clients are built from it.
Rpc::with_pool_idle_timeout sets another bound, for a node with a shorter
idle close and for tests.

Every RELAY_METHODS call now goes through a second client that keeps no
idle connection, so each relay opens a new one. A relay can then fail only
to connect, which is provably unsent, or on the connection it just opened,
which is a genuine unknown rather than this race. A node with a shorter
idle close than the bound, or a proxy that drops idle connections, can no
longer race a relay. A relay is rare, and the new connection costs one
connect.

tests/rpc_idle_close.rs runs the real client against a loopback node that
drops a request arriving after its idle limit, as the race does, and counts
the connections it accepts. With a shorter bound, the next call opens a new
connection and is answered. With the old long bound, it reuses the stale one
and fails with the production error, which is not RpcNotSentError. A relay
call after the pause is answered on a new connection even with the long
bound. The migration guide notes the node-side requirement.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-09T21:53:05.417286Z 65d2692 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

…rom node_client_builder (review on #760)

A new connection for each relay put its connect inside submitblock's 1
second deadline (PRISM_BLOCK_SUBMIT_RPC_TIMEOUT_SECONDS). A deadline that
passes while connecting is a timeout, not a connect error, so the block
would count as an unknown offer and never be offered again: a lost SYN or a
slow accept would cost a block that never reached the node. A warm pooled
connection within the 20 second bound is the safer path, so relays share it
again, as they did before this PR.

Rpc's client now starts from node_client_builder(), like the public API's
and the load harness's. The pool_idle_timeout accessor and its test only
restated the constant, so they are gone. The docs name a proxy's idle
timeout beside qbitd's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RobertClarke RobertClarke changed the title DO NOT MERGE without coordinator GO: 3.x.x: drop an idle node connection after 20 s, below qbitd's 30 s idle close, and send each relay call on a new connection (#759) DO NOT MERGE without coordinator GO: 3.x.x: drop an idle node connection after 20 s, below qbitd's 30 s idle close (#759) Oct 9, 2026
@RobertClarke
RobertClarke merged commit 12f1ae8 into 3.x.x Oct 9, 2026
39 checks passed
RobertClarke added a commit that referenced this pull request Oct 19, 2026
The notes cover everything since v3.0.0-rc.6: #770's import-audits fix
(#765) and #760's idle-connection bound (#759), which would have shipped as
rc.7, and the 3.1 dual writer (#766, #768, #767, #769, #763), off by
default. They describe the new settings, migrations 027, 028 and 031 (029
and 030 reserved), the upgrade from rc.6 with the migrate run while rc.6
serves, the rollbacks, and the dual writer's known limits. The migration
guide's import-audits paragraph names this candidate in place of the
skipped rc.7.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
RobertClarke added a commit that referenced this pull request Oct 20, 2026
* 3.x.x: version 3.1.0-rc.1

VERSION, the workspace version and both lockfiles move to 3.1.0-rc.1.
The fuzz lockfile also picks up hyper and hyper-util, which #769 added to
the server without refreshing it. The 3.0.0 and development-line notes
point at the new candidate; its own notes follow in this pull request.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* 3.x.x: 3.1.0-rc.1 release notes

The notes cover everything since v3.0.0-rc.6: #770's import-audits fix
(#765) and #760's idle-connection bound (#759), which would have shipped as
rc.7, and the 3.1 dual writer (#766, #768, #767, #769, #763), off by
default. They describe the new settings, migrations 027, 028 and 031 (029
and 030 reserved), the upgrade from rc.6 with the migrate run while rc.6
serves, the rollbacks, and the dual writer's known limits. The migration
guide's import-audits paragraph names this candidate in place of the
skipped rc.7.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* 3.x.x: 3.1.0-rc.1 notes: #773's pre-migrate tests

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* 3.x.x: 3.1.0-rc.1 notes: the rollback to one writer stops and syncs the peer first

Codex on #774: DOWNGRADE fences nothing, so the peer must be stopped, and its
tail pulled, before the single-writer start; declare the tail lost only for a
peer that never returns with its own database.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
kiwidream added a commit that referenced this pull request Oct 22, 2026
* 3.0.x: version 3.0.0 and its release notes (#557)

3.0.0 is 3.0.0-rc.6 plus #770 (#765) and #760 (#759), the two fixes
#772 prepared as 3.0.0-rc.7, which was never tagged. The 3.0.x branch
starts at #770's merge, 4c13491, before 3.x.x took the 3.1 dual writer.

- VERSION, [workspace.package].version and the workspace-member entries
  of both Cargo.lock files move to 3.0.0.
- doc/release-notes-3.0.0.md becomes the 3.0.0 notes: #772's rc.7 notes
  as the changes since rc.6, then the D5 recovery contract it held.
- The development-line note and the migration guide name 3.0.0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* 3.0.x: update rustls, rustls-webpki and webpki-roots for six RustSec advisories

cargo deny fails on rc.6's lockfile with RUSTSEC-2026-0346, -0347, -0348
and -0349 (rustls < 0.23.46), RUSTSEC-2026-0382 (rustls-webpki
< 0.103.16) and RUSTSEC-2026-0381 (webpki-roots < 1.0.10). Move each to
its first fixed patch release with cargo update --precise, in the root
and fuzz lockfiles, as #354 did for RUSTSEC-2026-0285. No other
dependency changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* 3.0.x: describe 3.0.0 as this line's production release

The development-line note's status, not-done and upgrade sections, and
the README banner, said no production release of the Rust server
existed. With the coordinator's go-ahead for 3.0.0 they now point to
3.0.0 on 3.0.x and its notes, and say 3.x.x continues as 3.1. The 3.0.0
notes list the TLS dependency update.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
@RobertClarke
RobertClarke deleted the RobertClarke/759-rpc-pool-idle-bound branch November 3, 2026 20:46
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.

1 participant