Race condition if two worker instances attempt to initialize clean database in parallel
- Dominant language
- TypeScript
- Stars
- 2.4k
- Forks
- 126
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 9
Description
Only affects first run of worker against your DB, so if you already have worker running you're fine.
If you run 10 `graphile-worker` instances against a clean database all at the same time there's a good chance that in this code:
https://github.com/graphile/worker/blob/436e29968d28c48d5f46a012b9c83b0747e2eff1/src/migrate.ts#L117-L137
two or more will generate the requisite `42P01`/`42703` error, and both will attempt to install the schema, and only one can succeed. The other will throw an error and exit.
There's two bugs here:
1. the `installSchema` should be wrapped with `try/catch` so that errors thrown there will trigger a retry of the whole loop
2. there's no `sleep()`, so it'll instantly retry which can be painful - we should use randomized back-off
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.