Skip to content

3.x.x: make the live_regtest port-reservation, failover share-count and weighted-recipients RPC waits deterministic under load (#533) - #563

Merged
djh58 merged 1 commit into
3.x.xfrom
djh58/prism-b-flakes-live
Sep 29, 2026
Merged

djh58 merged 1 commit into
3.x.xfrom
djh58/prism-b-flakes-live

Conversation

@djh58

@djh58 djh58 commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Makes the three load-sensitive live_regtest cases from #533 deterministic. Test-only: no production code changes, and no assertion is removed or loosened.

fixture_ports_stay_reserved_until_their_child_starts: "Address already in use"

Cause. The test proved that a release works by binding the released ports again, and that dropping the reservations works by binding the rest. A released port goes back to the host at once. In the full binary, the concurrent live tests start children on ports from free_port() and take their own reservations, and any of them can bind a released port first. The test's own bind then failed with Address already in use (os error 98).

Fix. The release is now checked on the reservation's own sockets, not on the host's port table:

  • after release, the held set is exactly the unreleased ports;
  • the unreleased ports still refuse a bind, as before;
  • on Linux, the released ports' listening sockets are closed and the others are still open, identified by socket inode (the descriptor number would be reused by the next open);
  • dropping the reservations closes every socket.

real_two_server_mining_failover_audit_and_reorg: API share-count read race

Cause. After quiesce() (miners killed, candidate outbox drained), the test read the accepted-share count, then the credited-header count, then each server's /audit/latest. A submission a server had read before its miner was killed can still commit between those reads. The API then reports one more share than the count read before it, or the header count differs by one from the share count.

Fix. Both counts come from one statement, so they share a snapshot, and count == unique stays exact. Each API count must equal a share count that is the same before and after the two API reads. If a late commit lands in between, the check is repeated for up to 30 s. A wrong API count still fails, now with both counts in the message.

real_weighted_recipients_pay_exact_pplns_outputs_through_fanout_spend: operation timed out

Cause. The difficulty ramp mines in 250-block generatetoaddress batches through the fixture client, whose timeout is 45 s. At a host load average of 50–60, the node connected about 5 blocks a second, and one batch outran the timeout. The error was error sending request for url (…/), raised while the servers' logs showed the ramp's heights still advancing. The payees' many-input sendall is the file's other heavy call.

Fix. generatetoaddress (the new generate helper) and the file's wallet_rpc carry their own 600 s per-request deadline, HEAVY_RPC_TIMEOUT. Neither call is idempotent, so neither is retried. Fixture reads keep the 45 s client timeout.

Evidence

Every run pins the test binary, its qbitd and servers, and the private PostgreSQL 16 (fsync on) to the same two cores.

Injected faults. Each fault is identical in the before and after builds:

Case Fault Before After
ports another socket binds a released port right after release Address already in use (os error 98) pass
failover after the count read, a miner runs until one more share commits API does not expose cluster share count pass
weighted fixture client timeout 450 ms times out in the ramp (a generatetoaddress batch) pass
weighted fixture client timeout 700 ms times out at sendall pass

Mutants. Each mutant was run against the fixed tests:

Mutant Fixed test fails with
release drops the entry but leaks the socket the socket-inode check for the released port
release is a no-op the held-set check
the API's accepted_share_count is one too high API does not expose cluster share count 16 (then 16): … 17 after the 30 s bound

Stress. Each session was bounded, with 2 CPU burners on the two cores:

Test Runs Failures
ports, before (alone) 1000 0: the race needs a concurrent binder, so the injected fault above is the before-evidence
ports, after 1000 0
failover, before 10 0
failover, after 63 0 share-count failures; 4 failures of a different, pre-existing mode (below)
weighted, after 8 0 (≈136 s each under the burners, so a smaller sample)

A separate mode, tracked in #562 and not changed here. Under the burners, the failover test sometimes fails earlier, at timed out waiting for surviving server mining. That is the 20 s wait for server 1 to gain three shares after server 0 is killed, and it comes before the code this PR touches. In regtest every share meets the block target, so server 0 is almost always mid-landing when it is killed. In each failure, server 1 then logged nothing and answered no submission for the whole window.

CI runtime

No measurable change. The loop in the failover test normally finishes in one pass. The deadlines only lengthen how long a heavy call may take, and add no waits.

Checks

  • cargo clippy --locked -p qbit-prism-server --test live_regtest -- -D warnings: clean.
  • cargo fmt --all --check: clean.
  • /code-review medium: no findings.
  • test/prism-gated-tests.txt is unchanged, because no test id changed.

Closes #533
Refs #562

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

…nd weighted-recipients RPC waits deterministic under load (#533)

fixture_ports_stay_reserved_until_their_child_starts proved a release by
binding the released port again. A released port goes back to the host, and
a concurrent test's free_port() child or reservation can bind it first, so
the bind failed with "Address already in use". The test now checks the
reservation's own sockets: exactly the released ports leave the held set,
their listening sockets are closed (by socket inode, on Linux), the others
stay open and still refuse a bind, and dropping the reservations closes
every socket.

real_two_server_mining_failover_audit_and_reorg read the accepted share
count, then the two API counts, right after stopping the miners. A share a
server read before its miner was killed can still commit in between. The
count and the credited-header count now come from one snapshot, and each
API count is compared with a count that is the same before and after the
API reads, retried for up to 30 s. A wrong API count still fails.

real_weighted_recipients_pay_exact_pplns_outputs_through_fanout_spend's
difficulty ramp mines 250 blocks per generatetoaddress; at a host load
average of 50 one batch outran the fixture client's 45 s timeout. That
call and the file's wallet calls (the payees' many-input sendall is the
other heavy one) now carry a 600 s per-request deadline. Neither is
idempotent, so neither is retried.

Test-only. Closes #533. Refs #562.

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

djh58 commented Sep 28, 2026

Copy link
Copy Markdown
Member Author

Review ledger (#533)

This PR changes tests only, so under the current policy it got a proportionate check rather than a full deep review: one /code-review medium pass, injected-fault and mutant evidence, and bounded 2-core stress runs (all in the PR body).

Review findings

# Finding Disposition
— /code-review medium: no findings. —
1 CI shard 2 failed on the first run, in weighted_recipients_tests::real_weighted_recipients_pay_exact_pplns_outputs_through_fanout_spend, with timed out waiting for every fanout confirmed in the read model. Not caused by this PR; the root cause is tracked in #569. The failing 60 s wait starts after the last mine(1) returns, and this PR only lets heavy RPCs take longer before failing, adding no waits. The same failure reproduces with the base test code under 2-core stress (2 of 4 runs). Cause: when a payout revision bump lands between a CTV attempt and finish_fanout, the completion fails, run_once returns early, and the fanout stays claimed for its 120 s claim with no retry. The shard passed on rerun.

The review also checked the following and found them sound:

  • assert_eq!(held, ports[2..]) holds because retain keeps order.
  • The socket-inode checks tell released listeners from held ones and tolerate concurrent descriptor churn.
  • The Linux-only code is gated consistently.
  • The one-snapshot count/unique read is exact.
  • The share-count loop requires a count that is stable across both API reads and is bounded at 30 s.
  • The per-request HEAVY_RPC_TIMEOUT overrides the client default, and neither non-idempotent call is retried.

Bots: [code]smith skipped. No other review comments.

Separate mode noted in the PR body

timed out waiting for surviving server mining under heavy host load is tracked in #562 and is unchanged here.

CI

All required checks green on the PR head.

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