Repository navigation
Send a stopping node's handed-off requests to the new owner by retry - #8826
piscisaureus wants to merge 3 commits into
Conversation
An actor call's attempt now knows whether, and for how long, a failure before it reaches the actor would be sent again: the call has retries enabled, an attempt left, and time left in its retry timeout once the next retry's longest backoff has passed. A fetch passes that on to the actor channel as `SubrequestMetadata::actorRetryBy`, a time by the monotonic clock. A JS RPC call sets none: it commits to its attempt once a call is pipelined on its result, which can happen while the attempt is in flight, and from then on retries nothing. A channel that forwards the request can use this to choose between failing it as not delivered, which the caller then sends again, and forwarding it itself.
WorkerdBootstrap.startEvent gains `actorRetryWithinNs`: how long from when the request is sent its caller sends it again if it fails before it reaches the actor (`SubrequestMetadata::actorRetryBy`), or zero if it does not. It is a duration rather than a point in time because the two ends' clocks differ. A cluster session or the debug port's actor client sends it with each request, and the receiving end turns it back into a point in time by its own clock, so that a peer that receives the request can tell whether, and for how long, the caller sends it again. An older sender leaves it zero, so the request reads as one its caller does not send again; an older receiver ignores it.
There was a problem hiding this comment.
Superseded by the review of
331cb8de.
This review, of ab6235c4
✅ Approved — No correctness, security, performance or documentation issues found. The retry window is a clamped duration, and it falls back to relaying for old peers and for requests that cannot be retried.
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
The new field comes from a cluster peer and is clamped before use. The worst a peer can do with it is make a draining node answer moved early, and the caller then retries. The change touches no authorization, injection or secret-handling code.
📖 AGENTS.md: ✅ LGTM
No issues found.
📋 Code Quality: ✅ LGTM
retryWithin(): it reuses theattemptCount - 1indexing thatretryDelayalready uses. It returnsnonein these cases:- JS RPC calls
- retries turned off
- no attempts left
- a timeout shorter than the next retry's longest backoff
- Wire field:
actorRetryWithinNsis a duration, so it does not depend on the two nodes' clocks. The receiver treats 0 or an unset value as "no retry" and clamps the value to 60 seconds. - Draining node:
retried_in_timeruns after the handoff wait. It compares the retry time left at that point with the time left until the relay cutoff, plusHANDOFF_RETRY_MARGIN, and it returns false while the node is not stopping.
⚡ Performance: ✅ LGTM
The change adds one constant-time comparison on a path that already waits for a handoff.
📝 Documentation: ✅ LGTM
No issues found.
Reviewed commit: ab6235c4
A draining cluster node relayed a peer's request that had waited for its Durable Object's handoff to wherever the object went. The relay could outlast the node: under load, the new owner's takeover (claiming the object and reading its log back from the bucket) took longer than the time from the in-flight deadline, before which the relay starts, to the connections deadline, at which the node exits. The node then exited with the relay in flight, and the peer saw "Peer disconnected", which it treats as a request that may have run, so its caller got a 500 instead of a retry. "a node stopping under load hands its DOs to its peers" failed so in CI. Such a request is now answered `moved` instead, before anything runs, when its caller sends it again for longer than a relay would have: the request says how long its caller still retries a failure before delivery, and that is at least the time to the node's connections deadline, which cuts a relay off, and 1 s more. Too small a margin, and a caller answered moved runs out of time to retry: it must cover the request's way to the node, which the receiver anchors the caller's time after and so cannot see, with any queueing on the busy draining node; the answer's way back; and the retry's routing, which may read the owner from the bucket. Too large, and requests are relayed that a retry would have saved, with less time for the takeover; with the defaults (an 8 s stop, a 10 s retry timeout), 2 s would leave a caller only some 0.3 s of slack, so most such requests would be relayed. Measured between two nodes of a test cluster, one way took under 100 ms (p99 55 ms), with every core busy too; 1 s is about five times both ways, which leaves room for the routing. The caller then sends the request again where the object went, without the draining node, and has at least as long for the takeover as a relay would. A fixed minimum alone would answer moved to a caller whose retry timeout ends during a takeover that a relay would have outlasted. Any other request is relayed until the in-flight deadline, as before: one from an older node, which says nothing; a fetch with retries off, with a streamed body, or whose retry timeout ends before a relay's time would; and a JS RPC call, which can commit to its attempt while it is in flight. Those keep the exposure to a takeover that outlasts the node. A new test has the new owner's restore read the object's log back slowly. It fails on "Network connection lost" without this change. Its fault matches only the new owner's reads, through an endpoint path the fake S3 strips, so that the old owner's compaction, which its handoff waits for, is not slowed. It reports when the request reached the old owner too late to wait for the handoff. Another has a 6.5 s retry timeout and a takeover that outlasts the retry but not a relay: it is relayed and succeeds. It holds the object long enough for the request to wait for the handoff, some 3 s, and reports a request sent after the handoff ended instead of failing on it. The test of requests that wait for a handoff now sends them once the handoff started, with the object held longer, and also checks that a peer's request with a long retry timeout is answered moved, and that ones with a streamed body, with `maxRetries: 0`, or with a retry timeout that ends before a relay's time would are relayed and succeed.
ab6235c to
331cb8d
Compare
There was a problem hiding this comment.
✅ Approved — No correctness, security, performance or documentation issues found. The retry window is a clamped duration, old peers and requests that can't be retried still get relayed, and the follow-up changes to the margin and the test timing address the earlier comments.
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
actorRetryWithinNs comes from a cluster peer and is clamped to MAX_CONFIGURABLE_TIMEOUT before it is used. Zero or an unset value means the caller does not retry. The worst a forged value can do is make a draining node answer moved early, and the caller then retries.
📖 AGENTS.md: ✅ LGTM
No issues found.
📋 Code Quality: ✅ LGTM
No issues found.
retried_in_time(actor.rs): it compares the retry time left with the time until the relay cutoff, plusHANDOFF_RETRY_MARGIN. It returns false while the node is not stopping.- Margin documentation: the doc comment now describes the cost of a margin that is too small and of one that is too large.
- Test timing: the timeouts in the cluster tests leave slack on both sides:
- the 6 s retry-timeout case is relayed;
- the default-policy case is answered
moved.
- Unit tests:
retryWithin()is covered for FETCH and JS RPC calls, retries off, a non-replayable body, a short timeout and the last attempt.
⚡ Performance: ✅ LGTM
The change adds one constant-time comparison on a path that already waits for a handoff.
📝 Documentation: ✅ LGTM
No issues found.
Reviewed commit: 331cb8de
A draining cluster node should not turn a retriable Durable Object
handoff into a 500. Until now, a draining node relayed a peer's
request after it had waited for the object's handoff. Under load, the
new owner's takeover could outlast the draining node, so the node
exited mid-relay and the caller got a 500
(
Network connection lost.) instead of a retry. This made the clusterintegration test "a node stopping under load hands its DOs to its
peers" flake in CI, most recently on an asan job.
The caller now tells the node how much retry time remains. After a
peer's request waits for a handoff, the draining node answers
movedbefore anything runs only when the caller will retry for longer than
a relay has before the node's connections deadline, plus a 1 s
margin. Otherwise, it relays the request as before.
The margin covers what the node cannot see or measure: the request's
way to it, including queueing on the busy draining node, the answer's
way back, and the retry finding the new owner, which may read the
owner from the bucket. One way between two test nodes measured under
100 ms even with every core busy. A larger margin would relay requests
that a retry would have saved: with the defaults (8 s stop, 10 s
retry), 2 s would relay nearly every default-policy request.
Measuring against the connections deadline, rather than requiring a
fixed amount of retry time, keeps
movedfrom going to callers whoseretry timeout would end during a takeover that a relay outlasts.
Requests still relayed
The node continues to relay:
These requests retain the previous exposure to a takeover that
outlasts the draining node.
Compatibility
The new Cap'n Proto field,
actorRetryWithinNs, carries a durationbecause clocks differ between nodes. Receivers clamp it to 60 seconds.
An old sender leaves the field unset, so its requests are relayed as
before. An old receiver ignores the field.
Tests
the fix, it fails with
Network connection lost.succeed.
moved), astreamed body,
maxRetries: 0, and a short timeout (all relayed)."handing off" log before sending, and hold it long enough that a
slow runner's request still arrives during the handoff.
The load test, "two nodes stopping at once under load", the
waited-handoff test, the slow-new-owner test and the brief-retry test
passed 30 runs in a row (150 of 150). The full cluster, server, and
actor retry test sets pass.
Lines changed