Repository navigation
Synchronize web VFS last_error_ across threads - #20
Merged
Merged
Conversation
The shared VFS object's std::string was written by Open/FetchDatabaseHeader error paths and read by xGetLastError and logging with no synchronization; ThreadSanitizer caught concurrent writes through the string internals and a write-vs-read through GetLastError's strncpy during a failed-open storm. Guard set/get with a mutex (mirrors the nested-VFS C5 fix); error text and codes unchanged.
Wid-L-Hacker
marked this pull request as ready for review
October 24, 2026 19:15
Wid-L-Hacker
added a commit
to Wid-L-Hacker/sqlite_web_vfs
that referenced
this pull request
Oct 25, 2026
Resolves the FetchDatabaseHeader conflict with main: the branch's geometry-first Content-Range validation, with its error paths in main's SetLastError form (from mlin#20's last_error_ synchronization). The resolved file is byte-identical to a local merge of main (80dee60) into this branch, verified by building and testing the merged tree (74 unit assertions, 9/9 origin tests, lint green).
Wid-L-Hacker
added a commit
to Wid-L-Hacker/sqlite_web_vfs
that referenced
this pull request
Oct 25, 2026
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.
The web VFS shares one last-error string across connections but accesses it without synchronization. Concurrent error reporting can corrupt the string, not just mix up messages. This is the web counterpart of the nested-VFS race addressed in sqlite_zstd_vfs #19 (C5).
What happens today
Error paths in
Open()andFetchDatabaseHeader()writelast_error_. It is read through thexGetLastErrortrampoline and bySQLITE_VFS_LOGcall sites. Under a failed-open storm — many threads opening databases against a failing origin at once — ThreadSanitizer reported write-against-write races inside the string's internals, and a write racing thestrncpyinGetLastError().The fix
A mutex now guards the string. The write sites set the message through a small
SetLastError()helper, andGetLastError()copies the message out while holding the lock. Existing error strings and explicit return codes are unchanged; only the synchronization is new.How it was verified
ThreadSanitizer, before and after, on the same storm workload (40 successful opens, 400 failed opens, 12,000 rows read back). The pristine build reports the race family described above. The patched build reports zero races in
web_vfs.h, with identical functional outcomes.Point for review
The mutex preserves the existing shared-slot semantics and mirrors the nested-VFS fix. The alternative is
thread_localstorage, which gives each thread its own error slot. If you prefer it here, the nested-VFS fix in sqlite_zstd_vfs #19 should change to match.Found during follow-up review of the 2026-10-23 audits.