Repository navigation
fix(studio): serialize SQLite connection closes (#10022) - #10069
danielhanchen merged 4 commits into
Conversation
Gate studio.db opens as well as closes: SQLite 3.51.0-3.51.1 also deadlocks a WAL close against a concurrent open (findReusableFd), so a close-only gate still hangs. Route the library_db and account_access studio.db openers added on main through the same gate, make it reentrant and reset it after fork, and drop the setup-failure refactor.
|
Pushed 57e6d1f: merged current main (conflicts resolved) and reworked the gate. The hang in #10022 is an upstream SQLite bug in 3.51.0 and 3.51.1, fixed in 3.51.2 (
So closing alone is not enough: Related backend suites show the same failing test IDs on main and on this branch (pre-existing, missing |
|
Review record for #10069, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#395. Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found. Round 1: reviewed mirror
|
Summary
Serialize opening and closing
studio.dbconnections behind one process-wide lock, so Studio no longer hangs on SQLite 3.51.0 and 3.51.1.Those SQLite releases can deadlock when one thread closes a WAL connection while another thread opens or closes a connection to the same file:
unixIsSharingShmNodetakes the VFS mutex while holding the inode mutex, the reverse order ofunixCloseandfindReusableFd. SQLite fixed it in 3.51.2, but Python builds bundling 3.51.0/3.51.1 are still in use (the reporter is on 3.51.1).Changes
storage.studio_db.connect_studio_dbopens connections under the lock and returns asqlite3.Connectionsubclass whoseclose()takes the same lock. The lock is reentrant and reset in forked children.studio_db,providers_db,mcp_servers_db,credential_secrets,library_db, and the model grant reads/writes inaccount_access.Testing
C stress test (threads looping open, read, close on one WAL file), 3 runs per row:
test_studio_db_factories_serialize_connection_closechecks every factory goes through the gate for both open and close, with at most one holder at a time; it fails when only close is gated.get_connectionopen/close with 8 threads: about 0.9 ms per op vs 1.1 to 1.2 ms on main; single thread unchanged.Fixes #10022