Repository navigation
fix: serialize concurrent PostgreSQL schema initialization - #53
Merged
Merged
Conversation
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.
Four simultaneous connections to an empty PostgreSQL schema reproduced three
pg_type_typname_nsp_indexfailures. MCP's independent reader workers can trigger this race becauseCREATE TABLE IF NOT EXISTSdoes not serialize first-time catalog creation.Initialization now takes a transaction-scoped advisory lock for the current database/schema, commits it with the schema, and rolls back on failure. The backend factory closes a connection if initialization fails, rather than returning/leaking an aborted backend. Existing storage operations retain their transaction behavior.
Tests exercise four synchronized independent initializers on an empty real PostgreSQL schema, connection reuse after a failed initialization, and factory cleanup for both backends. Validation: full macOS suite 2,122 passed / 111 skipped; Linux aarch64 with real PostgreSQL 16.15 2,190 passed / 43 skipped; Ruff and all six CI checks passed. The reproduced four-connection race changed from three failures to four successes. Four simultaneous imports through the live MCP stdio server into a fresh PostgreSQL database also succeeded, storing four distinct runs.