Repository navigation
fix: take a PR's project locks all or nothing - #2768
Open
dannysauer wants to merge 1 commit into
Open
dannysauer wants to merge 1 commit into
dannysauer wants to merge 1 commit into
Conversation
The backend locked a PR's projects one at a time and stopped at the first project another PR held, keeping the locks it had already taken. Two PRs that both changed projects a and b could each hold one and fail on the other, until someone ran `digger unlock`. Each lock was also a separate check and insert, so two PRs planning at once could both take the same project. Plan, apply and lock now check every project before taking any. If another open PR holds one, the PR takes none and the comment names the first locked project and its holder, in the wording it had before. The checks and inserts run in one database transaction that also holds a per-repository Postgres advisory lock, so two PRs can't interleave, and a failure, panic, lost lock or crash commits nothing. Unlocks take the same lock, so a merged PR's unlock can't delete a lock another PR just took. Postgres disconnects a holder idle for more than a minute. A PR that can't get the lock in a minute, or hits a database error, is told to try again, in wording that isn't mistaken for a lock held by another PR. Every backend path that takes PR locks goes through one helper: GitHub comments and PR events, GitLab, Bitbucket, and the EE drift hook, which now also respects pr_locks. Closes diggerhq#2759. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
Closes #2759. Two PRs that both change projects
aandbcan no longer lock each other out. A plan, apply ordigger locknow checks every project before taking any lock. If another open PR holds one, it takes none and reports the holder in the same wording as before. Otherwise it takes them all.How it works
Behavior changes
pr_locks: false, as the other lock paths already did.Known gap
Checking whether a holder's PR is closed is a VCS call made while the repository is locked. If it hangs, Postgres frees the lock after a minute, but the stuck request isn't cleaned up.
Testing
DIGGER_TEST_POSTGRES_URLis set, because CI has no Postgres service. I ran them against Postgres 16:aandbin opposite order, 20 times. Each time, exactly one gets both. With the advisory lock turned off, the test fails on the first race.backend_test.ymlif you'd like these in CI.digger.ymlreference, and two typo fixes.#2760 proposes
lock_scope: repository, which would lock every project through this same path. We run this on our self-hosted backend, and are happy to adjust it based on your feedback.🤖 Generated with Claude Code