Fix concurrent LiteDB access crash with lock() serialization#784
Merged
dangershony merged 4 commits intomainfrom Apr 29, 2026
Merged
Fix concurrent LiteDB access crash with lock() serialization#784dangershony merged 4 commits intomainfrom
dangershony merged 4 commits intomainfrom
Conversation
…rashes Agent-Logs-Url: https://github.com/block-core/angor/sessions/37952660-e30f-4b1e-882b-ac6fcffbf4ec Co-authored-by: dangershony <7487930+dangershony@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
dangershony
April 24, 2026 15:15
View session
dangershony
reviewed
Apr 24, 2026
Agent-Logs-Url: https://github.com/block-core/angor/sessions/15c37bd0-286c-4977-bdf8-0f9a9dcd18d1 Co-authored-by: dangershony <7487930+dangershony@users.noreply.github.com>
Copilot
AI
changed the title
Fix concurrent LiteDB access crash with SemaphoreSlim serialization
Fix concurrent LiteDB access crash with lock() serialization
Apr 24, 2026
dangershony
reviewed
Apr 24, 2026
The global lock caused unnecessary contention across unrelated collection types. The BsonMapper concurrency bug only affects concurrent deserialization of the same type, so a lock per collection type is sufficient. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…thread Replace lock() with SemaphoreSlim.WaitAsync() so the UI thread yields while waiting for the semaphore instead of blocking. Each collection type gets its own SemaphoreSlim via ConcurrentDictionary to avoid cross-type contention. Co-Authored-By: Claude Opus 4.6 (1M context) <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.
A single
LiteDatabaseinstance was shared across allLiteDbDocumentCollectionwrappers with no synchronization, causingInvalidOperationException: Collection was modified; enumeration operation may not executewhen concurrent reads/writes triggered mid-enumeration deserialization in LiteDB'sBsonMapper.Changes
LiteDbDocumentDatabaseobject _lock = new()field passed to everyLiteDbDocumentCollectionwrapperLiteDbDocumentCollectionobject syncLockin the constructor_collection(Insert,Update,Upsert,Delete,DeleteAll,FindById,Exists,Find,FindAll,Count) wraps the LiteDB call with alockstatementUpsertAsyncholds the lock across the full exists-check + insert/update sequence — eliminating the TOCTOU raceasyncsince all LiteDB operations are synchronous; they returnTask.FromResult(...)directly