Skip to content

fix(indexer): wrap event handlers in Prisma transaction to prevent poison-pill events (#168) - #178

Open
trenysx wants to merge 1 commit into
Cylo-Traders:masterfrom
trenysx:fix/poison-pill-transaction-168
Open

fix(indexer): wrap event handlers in Prisma transaction to prevent poison-pill events (#168)#178
trenysx wants to merge 1 commit into
Cylo-Traders:masterfrom
trenysx:fix/poison-pill-transaction-168

Conversation

@trenysx

@trenysx trenysx commented Aug 18, 2026

Copy link
Copy Markdown

Summary

Closes #168

Problem: Event handlers in persistEvent perform multiple separate prisma.* calls without a transaction wrapper. If a handler fails mid-way (e.g., investment.create succeeds but campaign.update throws), the partial writes remain committed while the idempotency-marking Transaction row is never written. On the next poll, the event is reprocessed but immediately fails on the unique constraint of the already-existing partial row — a permanent "poison pill" that spams error logs forever.

Solution: Wrap each handler's writes + the final Transaction row insert in a single prisma.(async (tx) => { ... }) so a partial failure rolls back cleanly and the event can be retried from a consistent state.

Changes in server/src/indexer/parsers/event-parser.service.ts:

  • persistEvent now uses $transaction to atomically execute the handler + Transaction row insert.
  • All 16 handle* methods + ensureUser now accept a transaction client ( x) parameter and use x.* instead of his.prisma.*.
  • Administrative/audit-only events (registry admin events) still fall through to the Transaction row creation inside the same transaction.

Tests added in event-parser.service.spec.ts:

  1. ransaction atomicity (poison-pill prevention) suite with two tests:
  • Simulates a mid-handler failure: verifies Transaction row is NOT created (event not marked processed), then retries the same event successfully with full commit.
  • Verifies event is only marked processed after the full transaction commits.

All 47 unit tests pass; sc --noEmit and eslint are clean.

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.

[Backend] Event handlers aren't wrapped in a database transaction, so a partial failure creates a permanently un-retryable "poison pill" event

1 participant