Repository navigation
fix(listener): prevent concurrent processing of the same event - #1101
Open
maxx-GENIUS wants to merge 1 commit into
Open
maxx-GENIUS wants to merge 1 commit into
maxx-GENIUS wants to merge 1 commit into
Conversation
- Update processed_events CHECK constraint in schema and migration 006 to allow 'PROCESSING' status - Wire claimEvent into EventSubscriber.processEvent to atomically acquire lock before processing - Add releaseClaim to EventDeduplicationService to clean up abandoned/aborted claims - Update concurrent processing unit tests verifying concurrency protection and claim release Closes Core-Foundry#1072
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
This PR prevents concurrent workers from processing the same event simultaneously and triggering duplicate downstream actions/notifications.
Root Cause
Previously,
EventSubscriber.processEventonly performed a non-exclusive check-then-act lookup (isDuplicate), allowing concurrent worker executions to interleave. Furthermore,EventDeduplicationService.claimEventattempted to write'PROCESSING'status toprocessed_events, but the SQLite table constraint only permittedCHECK (status IN ('PROCESSED', 'SKIPPED', 'ERROR')). This caused anSQLITE_CONSTRAINTcheck violation which fell back into the error handler, failing open and returningclaimed: trueto every racing worker.Changes
processed_eventsCHECK constraint inschema.sqland006-database-data-integrity.tsto include'PROCESSING'.releaseClaim(eventId, contractAddress)method to allow explicit cleanup of in-flight claims if a process is aborted or cancelled before completion.EventSubscriber.processEventfromisDuplicateto atomicclaimEvent, ensuring only one worker holds the processing claim.concurrent-event-processing.test.tscovering concurrent claims, lease expiry recovery, and explicit claim release.Verification
npx jest src/services/concurrent-event-processing.test.ts src/services/event-deduplication-service.test.tsinlistener:Closes #1072