fix: webhook race condition on hook creation #1175
Merged
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.
xref: go-vela/community#997
Currently, there is an inconvenient bug that our users experience when Vela processes a webhook:
This errors happens when we attempt to create a hook in the database that contains the same
number
andrepo_id
.This attempts to resolve that issue by creating a retry loop with backoff that will repeat the following operations:
Example
For the sake of discussion, I find examples helpful so let's say we have a repo where the last hook number is
10
.Using the example provided in the ticket, let's say we have two
push
events fire after a PR is merged:push
to the target branch for the PRpush
for the deletion event of the source branch from the PRIn this scenario, the Vela server would process each event concurrently and attempt to insert a
11
hook record but one of these webhooks will fail to be processed due to the conflict as displayed above. This resolves that issue because in that scenario, we'd fall back to looking up the last hook for the repo (11
) and updating the number to12
.