fix(initializer): keep auto-retry alive for transient tasks despite fatal or hung siblings#5
Merged
Conversation
xray — see through AI slop with deterministic architecture PR diff reviews |
shpookas
force-pushed
the
fix/initializer-retry-wedge
branch
from
July 20, 2026 09:53
be9ad33 to
8d97c4e
Compare
… is fatal (backport erpc#973) Backports upstream erpc commit a04655e (PR erpc#973) verbatim, adapted only for this fork's attemptRemainingTasks signature. The auto-retry loop exited permanently when State() returned Fatal, which happens when ANY single task is fatal (e.g. one misconfigured upstream with a chainId mismatch). Every transiently-failed sibling task was then abandoned until process restart. In production this meant an upstream that blipped during a daemonset rollout (robinhood-mainnet) stayed unregistered (network n/a) for two days while all its traffic escaped to a paid 3P fallback. The loop now stops only when every task is terminal (succeeded or fatal); a fatal task is terminal for itself only.
…sk defence) Upstream (erpc#973) still waits unbounded on WaitForTasks each retry round: one task hung inside its Fn (e.g. a client dial that ignores ctx and never returns) stays Running forever and blocks the retry loop for every other task. Bound each round's wait by TaskTimeout so a hung task only delays a round, never stops retries. Candidate for upstreaming.
…lock-then-wait deadlock) Stop() held tasksMu while waiting for the auto-retry goroutine, which itself acquires tasksMu inside attemptRemainingTasks. If the loop was blocked acquiring the mutex when the cancel landed, Stop waited forever. Cancel-and-wait now happens before taking the mutex. Present upstream as well; candidate for upstreaming.
shpookas
force-pushed
the
fix/initializer-retry-wedge
branch
from
July 20, 2026 10:03
8d97c4e to
42f6842
Compare
4 tasks
- Reap Running tasks past TaskTimeout to TimedOut so ignore-ctx Fns cannot wedge hasPendingWork forever; completion uses attempt-ID + CAS so a late return cannot clobber a newer retry. - State(): one fatal sibling no longer maps the whole Initializer to Fatal while others succeeded/recover — mix is Partial; all-fatal stays Fatal. - waitForTasks waits in parallel and distinguishes wait-context abort from a task that already finished as TimedOut; Wait surfaces TimedOut/Fatal errors via lastErr. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Follow-up pushed addressing the review risks:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context: on Jul 18 an internal-erpc daemonset rollout coincided with the robinhood-mainnet node being briefly unavailable. Its bootstrap chainId probe failed once and the upstream stayed registered as network n/a for two days, sending ~9.8M req/day to the paid Offchain Labs fallback, until we manually kicked the daemonset. ~190 upstreams currently sit in the same unregistered state after any restart.
Upstream erpc hit the same bug and fixed it in erpc#973 (a04655e). This PR is structured as three commits so the core fix stays rebase-friendly:
Backport of upstream fix(util): keep retrying recoverable tasks when a sibling task is fatal erpc/erpc#973 verbatim (adapted only for this fork's attemptRemainingTasks signature): the auto-retry loop no longer exits when State() == StateFatal (which one single fatal task triggers, e.g. a chainId mismatch on one misconfigured endpoint); it stops only when every task is terminal (succeeded or fatal). This is the fix for the robinhood incident. Taking upstream's exact shape means the next rebase onto upstream main merges clean.
Fork addition, candidate for upstreaming: bound each retry round's WaitForTasks by TaskTimeout. Upstream still waits unbounded, so one task hung inside its Fn (a client dial ignoring ctx) blocks retries of every other task forever - this matches our prod observation of a silently dead upstreams-registry retry loop (no fatal logs, no retry logs).
Fork addition, candidate for upstreaming: Stop() held tasksMu while waiting for the retry goroutine, which itself takes tasksMu inside attemptRemainingTasks - a lock-then-wait deadlock. Cancel-and-wait now happens before taking the mutex. Present in upstream main as well.
Regression tests: fatal sibling (reproduces the robinhood failure mode; fails without commit 1), hung sibling (fails without commit 2), late-scheduled task. Full util suite passes with -race; the four wedge-related tests pass 10x repeated with -race; go build ./... and go vet clean.