Repository navigation
Conversation
This branch has not been deployed
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.
Refs #496
On current
mainI could not reproduce the race from #496. As far as I can tell both points in the issue are already handled (the clash frominstallSchemais caught and retried, and there is a randomized sleep), so this PR only adds tests to keep that in place. There are no source changes.What I ran: a script that calls
runMigrations()N times in parallel against a freshly created, empty database and then drops it, on PostgreSQL 16 over a unix socket. I varied N from 3 to 60 and ran several of these at once under full CPU load, about 7,700 calls in about 620 empty databases in total. Every call resolved and every database ended with all 20 migrations. No unique violation, deadlock or missing relation escapedmigrate().The existing test "multiple concurrent installs of the schema is fine" already covers this in spirit, but it depends on timing, so it cannot show that the losing path is actually taken.
New file
__tests__/migrateConcurrent.test.ts:migrate()and block behind it, and the test waits for that throughpg_stat_activity. Then the first connection commits, and both blocked callers get the unique violation on the schema and must carry on. No luck involved.runMigrations()calls, three rounds, each round into a schema that does not exist yet, through the public API with one pool per call.I broke
migrate()three ways and ran the new file three times each. Rethrowing the clash error frominstallSchemafailed the deterministic test in every run and most of the parallel rounds. Skipping the install when the schema is missing, and removing23505from the clash codes, each failed all four tests. Reducing the loop to a single attempt is not caught here or by the existing test; it still ends in the right state because the migrations tolerate the clash themselves.Both migrate test files together passed 5 times in a row (9 tests), and tsc, eslint and prettier are clean. I added no changeset since nothing published changes; I can add an empty one if you prefer.
If you still see this with a particular setup (Postgres version, number of workers, a pooler in front), I am happy to try that exact case. If not, #496 may be ready to close.