Skip to content

Lock MDSQLiteConnection._updateBuffer before accessing it#76

Merged
LucDeCaf merged 5 commits into
mainfrom
update-buffer-lock
Jul 8, 2026
Merged

Lock MDSQLiteConnection._updateBuffer before accessing it#76
LucDeCaf merged 5 commits into
mainfrom
update-buffer-lock

Conversation

@LucDeCaf

@LucDeCaf LucDeCaf commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Fixes #75.

The FlushUpdates method in MDSQLiteConnection enumerates the _updateBuffer property using LINQ, but this can fail if _updateBuffer is modified partway through the enumeration. It also calls _updateBuffer.Clear() at the end of the function, which means any updates triggered between _updateBuffer being enumerated and _updateBuffer being cleared are dropped.

This PR adds a lock around _updateBuffer and wraps all reads and writes of _updateBuffer in said lock. I considered using a ConcurrentQueue, but we would need a workaround for ConcurrentQueue.Clear() since that method doesn't exist in .NET Standard 2.0 (it would probably also be slower).

@Chriztiaan Chriztiaan self-requested a review July 8, 2026 08:43
Chriztiaan
Chriztiaan previously approved these changes Jul 8, 2026
@LucDeCaf LucDeCaf merged commit e94b5cb into main Jul 8, 2026
5 checks passed
@LucDeCaf LucDeCaf deleted the update-buffer-lock branch July 8, 2026 12:43
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.

MDSQLiteConnection.updateBuffer is not thread-safe — FlushUpdates() throws "collection was modified" racing the update hook

2 participants