Skip to content

Bootstrap a cluster peer session only once - #8593

Merged
piscisaureus merged 1 commit into
mainfrom
piscisaureus/cluster-bootstrap-once
Nov 20, 2026
Merged

piscisaureus merged 1 commit into
mainfrom
piscisaureus/cluster-bootstrap-once

Conversation

@piscisaureus

@piscisaureus piscisaureus commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

A cluster node could abort after a peer connection failed. A peer
session bootstrapped again for each Durable Object it reached through
getActor. Once the connection had failed with calls still out, such a
bootstrap started a new RPC connection over the same
TwoPartyVatNetwork, which still counted the failed one as busy.
capnp's check threw from the bootstrap call itself ("expected idle !=
this->idle"), and rpc_client_debug_actor(), which the Rust side
declares as unable to fail, aborted the node.

  • A session takes the peer's bootstrap once, as it connects, and every
    capability obtained over it starts from that one. On a failed
    connection, calls on it fail as disconnected, which the caller
    already treats as the session being down.
  • New worker-factory-rpc-test fails a session's connection with a
    getActor still unanswered, then gets another actor over the
    session and checks that its calls fail as disconnected. Without the
    fix it throws the same "expected idle != this->idle".

cluster-cron-test hit this in 2 of 120 runs with the pending cluster
lease and event-loop changes applied, and 0 of 160 with this fix. On
main it did not show in 80 runs, but nothing there keeps a session from
bootstrapping after a failure.

Kind Lines Where
Implementation 9 worker-factory-impl.h, -rpc.c++
Tests 92 worker-factory-rpc-test, BUILD.bazel
Documentation 0

@piscisaureus
piscisaureus requested review from a team as code owners November 18, 2026 06:07
@piscisaureus
piscisaureus requested a review from ry November 18, 2026 06:07

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of 435e826c.

This review, of d50d7779

💬 Approved with comments — A small, correct fix to how a peer session bootstraps. The only note, an INFO, is that no deterministic regression test covers the crash.

Findings: 1 info (1 is an inline comment on the diff)

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


📋 Code Quality: 💬 1 info

The fix is correct: the bootstrap is taken once in the Session constructor and reused. No regression test comes with it.

Recommendation: 💬 Optional Nits

  • [INFO] No regression test covers bootstrapping on a failed session. (src/workerd/server/factory/worker-factory-rpc.c++:214)
View full review

Correctness: no problems found.

  • worker-factory-impl.h: members are declared connection, then rpcSystem, then bootstrap, so they are built and destroyed in a safe order.
  • worker-factory-rpc.c++: both call sites cast the stored client. The types they get are the same as before.
  • No other code under factory/ calls rpcSystem.bootstrap().

Testing: the crash is only covered statistically, by cluster-cron-test runs. A deterministic test would guard against it coming back.


✅ All other checks passed

📝 Documentation: ✅ LGTM

The new comment on Session::bootstrap explains why the capability is obtained only once.


Reviewed commit: d50d7779

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of 66f8bdbb.

This review, of 435e826c

✅ Approved — A small, correct fix so a peer session bootstraps only once, now covered by a deterministic regression test. No problems found.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

No security concerns in this change.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md updates needed.


📋 Code Quality: ✅ LGTM

  • Session takes rpcSystem.bootstrap() once, and its members are built and destroyed in a safe order (connection, rpcSystem, bootstrap).
  • Both call sites use the stored client, and their types are unchanged.
  • The new kj_test fails the first call by dropping the peer's end of the pipe while that call is out. It then checks that an actor obtained afterwards fails with DISCONNECTED instead of throwing from a second bootstrap.

⚡ Performance: ✅ LGTM

Taking the bootstrap once per session also saves a bootstrap round trip for each later actor.


📝 Documentation: ✅ LGTM

The comment on Session::bootstrap explains why the capability is obtained only once.


Reviewed commit: 435e826c

@ry ry left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI] LGTM. Taking the bootstrap once is the usual capnp pattern, and the test is deterministic. A follow-up worth considering: the node aborted because the bridge declares rpc_client_debug_actor as returning KjOwn<RpcClient>, so any C++ exception there kills the process. Declaring it -> Result<KjOwn<RpcClient>> would turn the next surprise into a failed call.

@piscisaureus
piscisaureus force-pushed the piscisaureus/cluster-bootstrap-once branch from 435e826 to 66f8bdb Compare November 18, 2026 23:49
@piscisaureus

Copy link
Copy Markdown
Contributor Author

Done in 66f8bdb: rpc_client_debug_actor is declared -> Result<KjOwn<RpcClient>>, and ClusterNode::route passes the error on with ?, so a C++ exception there fails that request instead of the node. No test: with this PR, nothing in it throws on a broken session any more, so reaching that path would need fault injection. new_rpc_client and rpc_client_start_request are declared the same infallible way; I left them for a separate change.

@piscisaureus
piscisaureus requested a review from ry November 18, 2026 23:49

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of b23c2f7f.

This review, of 66f8bdbb

💬 Approved with comments — The fix is correct and the error now reaches the caller through ?. The only remaining note is an INFO about two comments that still describe the Rust caller as infallible.

Findings: 1 info (1 is an inline comment on the diff)

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


📝 Documentation: 💬 1 info

Two comments still describe the Rust caller as unable to fail.

Recommendation: 💬 Optional Nits

  • [INFO] Comment still says the Rust caller cannot fail and aborts, but rpc_client_debug_actor now returns Result. (src/workerd/server/factory/worker-factory-impl.h:264)
View full review
  • worker-factory-impl.h:263-264 and worker-factory-rpc-test.c++:51-52 say the Rust caller cannot fail and would abort. Since rpc_client_debug_actor now returns Result and route propagates the error, that is no longer true.

✅ All other checks passed

🔒 Security: ✅ LGTM

No security concerns in this change.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md updates needed.


📋 Code Quality: ✅ LGTM

  • Session takes the peer's bootstrap once, when it is constructed, and both call sites use that stored capability.
  • rpc_client_debug_actor now returns Result, and ClusterNode::route propagates the error with ?. route already returns crate::Result<Owner>, and other bridge calls in actor.rs use the same pattern.
  • The new kj_test is deterministic: it fails the session's connection while a call is still out, then checks that a later actor's calls fail as DISCONNECTED.

⚡ Performance: ✅ LGTM

Taking the bootstrap once per session also saves a bootstrap round trip for each later actor.


Reviewed commit: 66f8bdbb

A peer session bootstrapped again for each Durable Object it reached
through the debug port's getActor. Once the session's connection had
failed with calls out, such a bootstrap started a new RPC connection
over the same TwoPartyVatNetwork, which still counted the failed one
as busy. capnp's check of that threw from the bootstrap call itself
("expected idle != this->idle"), not as a disconnect of its calls,
and rpc_client_debug_actor(), which the bridge declared as unable to
fail, aborted the node.

* A session takes the peer's bootstrap once, as it connects, and
  every capability obtained over it starts from that one. On a failed
  connection, calls on it fail as disconnected, which the caller
  treats as the session being down
* The bridge declares rpc_client_debug_actor() as returning a Result,
  so an exception it throws fails the request being routed to the
  peer instead of aborting the node
* A worker-factory test gets an actor over a session that the peer
  reads and never answers, closes the peer's end, and checks that an
  actor obtained afterwards fails its calls as disconnected. Without
  the fix, its getActor throws "expected idle != this->idle"

cluster-cron-test hit this in 2 of 120 runs, in "a cron occurrence
does not run again on an owner whose clock lags", with the cluster
lease fixes and tokio running between busy KJ turns applied, changes
that are not on main yet. On main it did not show in 80 runs, but
nothing there keeps a session from bootstrapping after a failure.
@piscisaureus
piscisaureus force-pushed the piscisaureus/cluster-bootstrap-once branch from 66f8bdb to b23c2f7 Compare November 18, 2026 23:52

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Approved — The fix is correct and covered by a deterministic regression test, and the stale comment noted in the earlier review has been fixed. No findings remain.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

No security concerns in this change.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md updates needed.


📋 Code Quality: ✅ LGTM

The bootstrap is taken once per session, after the RPC system it depends on is built. Both call sites use the stored capability. The new test is deterministic.


⚡ Performance: ✅ LGTM

Taking the bootstrap once per session also saves a bootstrap round trip for each later actor. Holding one extra capability per session costs nothing meaningful.


📝 Documentation: ✅ LGTM

The comments in worker-factory-impl.h and in the test now describe only capnp's behaviour, which matches the code.


Reviewed commit: b23c2f7f

@piscisaureus
piscisaureus requested a review from jasnell November 19, 2026 23:17
@piscisaureus
piscisaureus merged commit 77ff05c into main Nov 20, 2026
23 checks passed
@piscisaureus
piscisaureus deleted the piscisaureus/cluster-bootstrap-once branch November 20, 2026 01:44
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.

3 participants