Skip to content

fix: serialize concurrent PostgreSQL schema initialization - #53

Merged
fcostaoliveira merged 1 commit into
mainfrom
fix/postgres-concurrent-initialization
Oct 23, 2026
Merged

fcostaoliveira merged 1 commit into
mainfrom
fix/postgres-concurrent-initialization

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Four simultaneous connections to an empty PostgreSQL schema reproduced three pg_type_typname_nsp_index failures. MCP's independent reader workers can trigger this race because CREATE TABLE IF NOT EXISTS does 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.

@fcostaoliveira
fcostaoliveira marked this pull request as ready for review October 23, 2026 21:02
@fcostaoliveira
fcostaoliveira merged commit 5799bec into main Oct 23, 2026
6 checks passed
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.

1 participant