Skip to content

state_exec: a closing group's late queue and forwarding addresses replace the poster's wait (S2b.R3) - #1561

Merged
transfix merged 2 commits into
masterfrom
perf/s2b-r3
Nov 26, 2026
Merged

transfix merged 2 commits into
masterfrom
perf/s2b-r3

Conversation

@transfix

Copy link
Copy Markdown
Owner

S2b.R3 fixes the skeptic's findings (K-1 to K-6) on S2b's R2 fixes, as a follow-up to #1524 and #1543. A closing group's handle now has a late queue, the teardown leaves per-key forwarding addresses, and a seal stops posters if the queue keeps filling. Together these replace the router's poster wait.

K-1 (major): overlapping teardowns

A group in its teardown never waited for another closed home (post_routed's may_wait). When a receiving group and its home tore down together, two things went wrong:

  • The receiver's requeue or taken reached the new home before the old home's adopt. A message another receiver had taken was queued again, and its tracker leaked.
  • The receiver's kill unsubscribed before the old home forwarded the record. The new home kept a record for a dead process, which kept the router on.

Waiting as the frozen text said would have deadlocked two homes tearing down at once, each holding an entry for the other.

The new rule is in exec_router.h ("Teardown and rehoming") and td 4.6:

  • Late queue. Once a handle is closed, a router entry posted through it goes into its late queue until the handle is done. That applies to any entry kind, from any thread, with no cap and no wait. group_ref::post_message, post_control and visit are refused once closed.
  • One target per key. The teardown sends each key's entries to a single target for the whole teardown. On the key's first entry, the target is the key's home among the groups still open (new_home_of), and then wherever that entry went. The order stays pending, records, trackers, queue, followed by the late entries until none are left.
  • Done. Under the handle's lock, the teardown unregisters, keeps each key's target as the handle's forwarding address, and marks the handle done. A poster that a done handle refuses goes on at once:
    • to the forwarding address (group_ref::forwarded), which it follows however long the chain;
    • else to home_of, except that a teardown's own forward goes to new_home_of, so its targets are open groups only;
    • else to new_home_of.
  • Seal. The teardown seals the handle when a round's batch doesn't shrink, when it reaches the ingress cap, or after 4 rounds. From then on only another teardown's forward is taken, and any other poster waits for done. A teardown's forward never waits, and what is left after the seal is finite, so the wait is bounded and no cycle of waits forms.
  • Why it terminates. Every target was open when it was chosen, so the only entry that can come back to a teardown is a deliver's requeue to its sender, at most once per entry. Two teardowns at once both end, and each entry reaches its key's state after the state.
  • What goes. The poster's backoff (C-M5), the host flag and the self-exemption (C-m1) are gone. So is exec_router.h's documented gap where a key's home changes twice while a broadcast is out: answers follow the old home's address.

Minors

  • K-2: a teardown's queued and late sends are forwarded only for keys the group homed: it registered a prefix once, and the key has no '#'. Otherwise they die, counted. The destructor's bounce (S2-Q10) is unchanged.
  • K-3: once its teardown begins (before the close), a group's post_message goes through its handle as a send. That means its ingress before the close, the late queue after, or the forwarding address once done. So it no longer sits in the dying ingress, and a host's posts keep their order whichever entry point they use. Posts that would have died in the queue ('#' keys, an island's own keys) die at once, counted, and return true as before.
  • K-4: a scope guard now runs to the end of exec_group's constructor.
  • K-5: three of the skeptic's probes are adopted.
  • K-6: recorded only, no code change.

Review

A read-only review (R3-1 to R3-9) found nothing major on a strict reading. Fixed:

  • seal when a batch doesn't shrink or reaches the cap;
  • post_message's order across the close;
  • the counted drops;
  • address hops no longer count against the 16 re-resolutions;
  • try_post reports why a post was refused, so a cap refusal is never retried past the cap;
  • closed-handle posts take only the late-queue mutex, and done is atomic;
  • documentation.

Recorded without a code change: a throw in leave_router drops the late queue (counted), and address chains keep their targets alive while an old handle is held.

Tests

  • 16 RouterR3 cases. Seven of the first twelve failed at master; the rest guard against regressions. The new ones cover the seal, a host posting through a teardown (20000 posts kept in FIFO order), a chain of 20 teardowns, and an island's post during its teardown. All are added to SAN_REQUIRED_S2B.
  • AnAnswerWaitsForItsClosedHomesForward becomes AnAnswerToAClosedHomeGoesAfterItsForward, and ATeardownNeverWaitsOnItself and ADeliverAClosedReceiverRefusesIsStaleAtOnce are updated to the new rule.
  • No case asserts on wall-clock time; threads have hang guards only.
  • The router model (tools/locks_model/router.py) models the late queue in place of the poster wait.
    • The quick suite runs 32 checks with 0 unexpected in 22 s, and test_router.py passes 10 tests.
    • The deep suite runs 49 checks with 0 unexpected in about 18 min.
    • The skeptic's teardown-no-wait mutation finds duplicate, stale-record and tracker-leak on all four configurations.
    • The model doesn't model the seal, because its scripts are finite.
    • locks-deep's router-model timeout goes from 45 to 90 minutes.

Local results (Windows, MSVC Release, cvcpkg prefix; at 1302cfb before the master merge)

  • Default slice and CVC_EXEC_SLICE_STEPS=256 give identical results. All pass: router 81, stress 2, exec_pool 87, groups 33, async 143, intrinsics 181, async_calls 83, priority 40, scheduler 200, exceptions 26, data_steps 54, hazards 12, integration 105, stackless 89, app 123, ariadne_host 54, ariadne_runtime 368, coordinator 76, locks 221.
  • pycvc (ctest -R pycvc, 68 tests). Every exec_pool and state_exec test passes. Three tests fail on this box for reasons unrelated to this change, and are left for CI's configuration:
    • volume_grid_contours: this build has no cvc::planar.
    • physics: it needs a gtest binary that wasn't built here.
    • net: this box doesn't raise on a port that's already taken.
  • The known slice-256 failure: pycvc_state_exec_locks PR08 fails at slice 256, as it has since S2b.0, because it assumes one step per pick.
  • Not checked here: TSan, ASan/UBSan, gcc, clang and Emscripten. CI covers those.

…lace the poster's wait (S2b.R3)

The skeptic's K-1: a group in its teardown never waited for another closed
home, so a receiving group torn down with its home sent its answers and
unsubscribes ahead of the home's forward. The result was a duplicate broadcast
delivery, a leaked tracker, and a dead process's record that kept the router on.
Making that teardown wait instead would deadlock two homes torn down at once.

- A closed handle takes router entries into a late queue until it is done.
  The teardown forwards each key's entries to one target, the key's home
  among the groups open when its first entry goes. It forwards the late
  entries until none are left, then unregisters under the handle's lock and
  keeps each key's target as a forwarding address. A refused poster follows
  that address at once. A teardown's own forwards go to open groups only, so
  nothing comes back to it except a deliver's requeue.
- The seal is a backstop for posters as fast as the forward. When a round's
  batch doesn't shrink, reaches the ingress cap, or 4 rounds have gone, only
  another teardown's forward is still taken, and any other poster waits for
  done, a bounded wait.
- K-2: a teardown's queued and late sends are forwarded only for keys it
  homed.
- K-3: once its teardown begins, post_message goes through the group's
  handle, keeping a host's order. A post that would die with the group dies
  now, counted.
- K-4: the constructor's guard spans the whole constructor.
- K-5: the skeptic's probes are adopted.
- The R3 review's fixes:
  - seal on a batch that doesn't shrink or reaches the cap;
  - try_post's refusal reasons;
  - address hops don't count against the 16 re-resolutions;
  - closed-handle posts take only the late-queue mutex, and done is atomic.
- The router model has the late queue in place of the wait, and the
  skeptic's teardown-no-wait mutation finds the three findings. The
  router-model job's timeout is raised to 90 minutes.
@transfix
transfix enabled auto-merge (squash) November 26, 2026 23:41
@transfix
transfix merged commit 4a113a3 into master Nov 26, 2026
30 checks passed
@transfix
transfix deleted the perf/s2b-r3 branch November 26, 2026 23:57
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