Fix indexer freeze when a single event fails to process (#1214) - #1378
Open
Hamda-gbade wants to merge 2 commits into
Open
Fix indexer freeze when a single event fails to process (#1214)#1378Hamda-gbade wants to merge 2 commits into
Hamda-gbade wants to merge 2 commits into
Conversation
A failing event used to freeze lastCursor for every subsequent event in the batch (the !hasError guard), so a single always-failing event reprocessed all later events on every poll indefinitely. The cursor now always advances past successfully processed events, and failed events are recorded in a new IndexerDeadLetterEvent table (raw payload, error, attempt count) for manual triage, with a retry cap (INDEXER_DEAD_LETTER_MAX_RETRIES, default 5) after which the event is abandoned and the cursor advances past it. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.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.
Summary
Fixes #1214 — a single failing Soroban event could freeze the event indexer permanently.
Root cause: In
fetchAndProcessEvents,lastCursor/lastLedgeronly advanced while!hasError. Once any event in a batch failed, the cursor stopped advancing for every subsequent event in that batch — including successfully processed ones. A single always-failing event (e.g. a malformed body) caused every later event to be re-fetched and reprocessed on every poll indefinitely, freezing the indexer and reprocessing the tail of the event stream forever.Changes
Indexer worker (
backend/src/workers/soroban-event-worker.ts)!hasErrorcursor guard. The cursor now always advances past every successfully processed event, even when an earlier event in the same batch failed.IndexerDeadLetterEventtable keyed by RPC event id, preserving the raw payload, the last error message, and an incrementedattemptscounter so operators can triage them manually.INDEXER_DEAD_LETTER_MAX_RETRIESenv var (default5). Once an event has failed that many times it is abandoned — logged, recorded in the dead-letter table, and the cursor advances past it so the indexer never stalls on a permanently-bad event.Schema & migration
IndexerDeadLetterEventmodel inbackend/prisma/schema.prisma(eventIdunique,ledger,transactionHash,rawPayload,errorMessage,attempts,lastAttemptAt,createdAt) with indexes on ledger, txHash, and createdAt.20260830000000_add_indexer_dead_letter_event. Deployed environments needprisma migrate deploy.Tests (
backend/tests/soroban-event-worker.test.ts)2) with the cursor advancing past it — the next poll re-fetches nothing.Docs
INDEXER_DEAD_LETTER_MAX_RETRIESand the dead-letter behavior inbackend/docs/SSE_ARCHITECTURE.md.Testing
tsc --noEmitclean; Prisma client regenerated.tests/workers.index.test.ts(stream-runway-worker mock gap) is unrelated to this change and reproduces on the base branch.Closes #1214