Skip to content

fix(initializer): keep auto-retry alive for transient tasks despite fatal or hung siblings#5

Merged
snowkide merged 4 commits into
feat/websocket-supportfrom
fix/initializer-retry-wedge
Jul 22, 2026
Merged

fix(initializer): keep auto-retry alive for transient tasks despite fatal or hung siblings#5
snowkide merged 4 commits into
feat/websocket-supportfrom
fix/initializer-retry-wedge

Conversation

@shpookas

@shpookas shpookas commented Jul 20, 2026

Copy link
Copy Markdown

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:

  1. 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.

  2. 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).

  3. 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.

@github-actions

github-actions Bot commented Jul 20, 2026

Copy link
Copy Markdown
File Lines Key changes Risk
🔴 initializer.go +200/-70 waitResult, reapOverdueRunningTasks, hasPendingWork ⚠ +3 primitives
1 test files +216

xray — see through AI slop with deterministic architecture PR diff reviews

@shpookas
shpookas force-pushed the fix/initializer-retry-wedge branch from be9ad33 to 8d97c4e Compare July 20, 2026 09:53
shpookas added 3 commits July 20, 2026 12:00
… 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.
- 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>
@jleeh

jleeh commented Jul 22, 2026

Copy link
Copy Markdown

Follow-up pushed addressing the review risks:

  1. Hung task reap — after each bounded wait, overdue Running tasks are force-transitioned to TaskTimedOut (retryable). Runner completion uses attempt-ID + CAS so a late return from an ignored-ctx Fn cannot clobber a newer attempt.
  2. State() — a single fatal sibling no longer makes the whole shared Initializer StateFatal while others succeeded/are recovering (Partial instead). All-fatal still Fatal.
  3. Parallel waitForTasks — siblings no longer serialize the wait budget; wait-context abort is distinguished from a task that already finished as TimedOut.
  4. WaitTimedOut/Fatal now surface lastErr (previously only Failed did on channel close).

go test -race ./util/ green.

@snowkide
snowkide merged commit defe2e4 into feat/websocket-support Jul 22, 2026
2 of 3 checks passed
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