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.
Fixes #580.
When concurrent callers schedule a job with the same key while an earlier job is
locked, one caller can finish the locked-job
UPDATEbefore another transactioninserts a locked row for that key. The following
INSERT ... ON CONFLICT DO UPDATE ... WHERE jobs.locked_at IS NULLthen returns no row.add_jobcan returna null ID, leaving the later scheduling request without a queued replacement.
This adds a transaction advisory lock for each distinct non-null job key before
the existing
UPDATEandINSERT. Batches acquire their key locks in sortedorder. Unkeyed jobs acquire no new advisory lock. The change is a new SQL
migration; existing migrations and the public API stay unchanged. The generated
SQL, schema snapshot, migration-count test, and patch changeset are included.
The new test uses a test-only
BEFORE INSERTbarrier to force the exact gap. Itfails on the existing SQL with
Received: nullfor the later call and passeswith migration
000021.Local preflight on Node 24 and PostgreSQL 14–18 passed the upstream CI functional
test stages on each version (24 suites, 106 tests, 19 snapshots per version).
The PostgreSQL 14 alternate-schema suite, TypeScript build, full lint, schema
dump, and Changesets status also passed. A separate bounded probe observed no
null IDs in 200 concurrent same-key calls; different keys proceeded independently;
and 40 reverse-order two-key batches returned all 80 rows without deadlock.
Each distinct keyed job in a batch holds one advisory lock until transaction
end. Isolated 3,000-key batches passed on PostgreSQL 14–18, and three concurrent
3,000/3,000/4,000-key transactions passed on PostgreSQL 17. These measurements
do not establish a production throughput or universal batch-size limit; the
shared advisory-lock pool and large-batch behavior deserve review. A transaction
with an older snapshot at
REPEATABLE READorSERIALIZABLEcan still receiveSQLSTATE
40001; the same scenario does so on the existing function, and callersat those levels need whole-transaction retry.
The repository's local
yarn testwrapper stops atdepcheckbecause it reportsthe existing
@changesets/changelog-githubdevDependency as unused. The CIfunctional test stages above completed independently. Hosted CI and maintainer
review have not run on this proposed patch.