fix(indexer): crash the process when the ETL indexer fails to start - #1042
Merged
Merged
Conversation
CoreIndexer.Start used a plain errgroup.Group, so an error from etlIndexer.Run() was recorded but never propagated: Wait() blocks until every goroutine returns, and AggregatesCalculator.Start only returns on ctx.Done(). With no context linking the two, a fatal ETL error left the process alive with block indexing permanently dead. This bit prod today. A GKE node upgrade restarted every pod at once; audiusd took ~67s to become ready, longer than the ETL's fixed 30x2s chain-ID retry budget, so Run() returned "initialize chain ID after 30 attempts" before indexBlocks() ever started. main.go panics on that error and k8s would have restarted the pod into a healthy audiusd, but Start never returned. The pod reported Running 1/1 for 8 hours while every other background job logged normally and the indexer sat 25k blocks behind, silently dropping plays, follows and every other on-chain write from the API's view. errgroup.WithContext cancels the sibling on the first error, so Wait() now returns the ETL error and main.go panics as intended. Graceful shutdown is unchanged: a SIGTERM-cancelled parent still surfaces as context.Canceled, which main.go ignores. The parity jobs move to the group context for the same reason — they should stop when the process is on its way down. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
What happened
Prod's core indexer stopped indexing at block 32,826,125 and stayed there for 8 hours. The pod reported
Running 1/1the whole time, with every background job (PrunePlays, IndexChallenges, Trending, …) logging normally. Plays, follows, and every other on-chain write were invisible to the API for the duration — this surfaced as a user's plays missing from the database.Timeline from the pod logs:
creator-1/audiusd-0createdapi/core-indexerstarts, begins resolving chain ID fromrpc.audius.co503 Service Unavailable, thencore service not readyaudiusdcontainer actually startserror initializing chain ID after 30 attemptsThe ETL's
initializeChainIDuses 30 attempts at a flat 2s delay — a fixed ~58s budget. audiusd took ~67s. It missed by about six seconds.Why it never recovered
InitializeChainIDruns inetl.Indexer.Run()beforeindexBlocks()is launched, soRun()returned the error immediately.main.go:58panics on that error, k8s would have restarted the pod into a now-healthy audiusd, and this would have self-healed in a minute.It never got there:
errgroup.Group.Wait()blocks until all goroutines return, and a plainGrouphas no context to cancel siblings with.AggregatesCalculator.Startonly returns onctx.Done(), and that ctx is cancelled only by SIGTERM. So the ETL's fatal error sat in the errgroup whileWait()blocked forever on a healthy infinite loop.Startnever returned and the process never exited.The fix
errgroup.WithContext, so the first error cancels the sibling andWait()returns it.main.gothen panics as it was always meant to and k8s restarts the pod.Graceful shutdown is unchanged: a SIGTERM-cancelled parent still propagates to
gCtx,Startreturnscontext.Canceled, andmain.goignores it. The parity jobs move togCtxfor the same reason — they should stop when the process is on its way down.Recovery is automatic
Resume is
GetLatestIndexedBlock() + 1frometl_blocks, so a restart replays the gap rather than skipping it. Confirmed on the restarted pod:block source: polling prefetcher start_height=32826126, exactly where it left off.Testing
Added
TestAggregatesCalculatorStartReturnsOnCancelledContext, which locks in the property the fix depends on: the sibling goroutine actually unblocks when its context is cancelled. If that loop ever stops honoringctx,Wait()silently goes back to hanging forever.The fix itself isn't unit-covered —
etlIndexeris a concrete*etl.IndexerandaggregatesCalculatorneeds live DB pools, so neither member is injectable without a refactor. Happy to add that seam as a follow-up if it's wanted.Follow-ups not in this PR
core-indexer. The deployment has no liveness, readiness, or startup probe, andmain.go'sindexercase doesn't start a health server the way thesolana-indexerandeth-indexercases do./health_check?max_core_indexer_block_diff=Nalready returns 500 on excess lag — nothing calls it. This is why a wedged process went unnoticed for 8 hours.SetCheckReadiness(true)is set, butawaitReadinessruns after chain-ID init and only logs on failure, so it can't help here.🤖 Generated with Claude Code