[327] Resolve race conditions in concurrent database_writer_pool calls - #388
Merged
1 commit merged intoAug 30, 2026
Conversation
…tions. Serialize identical event identities with in-memory queue locks while leaving unrelated events free to proceed, and always release those locks on success or failure. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@Goodnessukaigwe Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
9e42e6f
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
WriterPoolEventQueuewith per-event identity locks (contractId|ledgerSequence|eventType) so concurrentdatabase_writer_poolnotifications cannot both observe "not indexed yet" and insert the same row.queueWrite+INSERT OR IGNORE. Unrelated identities still persist concurrently; locks are always released on success and failure.queueWriteof unrelated operations remains on the existing sequential SQLite writer queue (one writer at a time) and is not serialized by event locks.Closes #327
Test plan
__tests__/database-writer-pool-concurrency.test.ts: concurrent submits insert each event once; same-key persists never overlap; unrelated keys run in parallel; lock released after success and after persist throw; overflow / reset / repeated waves.submitEventNotificationsof the same window do not duplicate rows; sequential resubmits are idempotent; store-levelINSERT OR IGNOREstill de-duplicates after a queue reset; racingqueueWriteinserts do not double-count.database-writer-pool*tests (91/91).tsc -p tsconfig.build.jsonandnpm run build.Made with Cursor