ConfigPersist race: concurrent webhook deliveries for one commit fail with a unique-constraint error and strand the pipeline in 'created'
Component
server
Describe the bug
ConfigPersist does a find-identical followed by an insert inside one session, but that pair is not atomic against a concurrent caller. When two webhook deliveries for the same commit are processed at the same time, both resolve the same (repo_id, hash, name), both miss on configFindIdentical, and both then call configCreate. One of them trips the unique index and the whole hook fails:
create.go:102 error="on insert duplicate based on constraints was detected"
message="failed to find or persist pipeline config for <org>/<repo>"
hook.go:229 message="could not create pipeline from webhook"
logger.go:57 method=POST path=/api/hook status=500 user-agent=GitHub-Hookshot/...https://github.com/woodpecker-ci/woodpecker/blob/main/server/store/datastore/config.go#L48-L70
existingConfig, err := s.configFindIdentical(sess, conf.RepoID, conf.Hash, conf.Name)
...
if err := s.configCreate(sess, conf); err != nil {
return nil, err
}The damaging part is not the 500 itself but what it leaves behind. The pipeline row has already been created by the time config persistence runs, so the losing delivery leaves a pipeline stranded at status: created with workflows: [] and started: 0. In the UI it looks like a pipeline that was accepted and simply never starts. It cannot be cancelled, and nothing in the repository or its config is wrong, so the natural reaction is to go looking at when: filters.
This is distinct from #3093, which is the same symptom one call later in linkPipelineConfigs (create.go:110) when two identical workflow files collide. Here there is a single config set and the collision is between two concurrent requests, in ConfigPersist itself (create.go:102). #1810 looks like the same family reached via cron.
How to reproduce
On GitHub, merging a pull request fires push and pull_request (closed) for the same commit, and they can arrive milliseconds apart. Observed in production:
13:00:17.162 configFetcher[<org>/<repo>]: use user config '.drone.yml' <- delivery A
13:00:17.175 configFetcher[<org>/<repo>]: use user config '.drone.yml' <- delivery B
13:00:18.367 failed to find or persist pipeline config ... POST /api/hook 500
13:00:18.399 marked as skipped, does not match metadata (delivery B, all workflows)
13:00:18.401 ignoring hook: 'when' filters filtered out all stepsDelivery A is the push; its pipeline is the one left stranded. Delivery B is pull_request_closed, which no workflow subscribes to, so it is correctly filtered — that filtering message is a red herring when reading the logs after the fact.
Frequency here: 9 occurrences in 24h across 3 merge-heavy repositories, out of a much larger fleet. It needs the two deliveries to overlap, so it is intermittent.
Expected behaviour
Two concurrent deliveries resolving the same config should both end up with the same config row. A losing race should not fail the hook or strand a pipeline.
Suggested fix
Make the persist idempotent rather than check-then-act, e.g. insert with ON CONFLICT DO NOTHING and re-select, or catch the constraint violation and retry configFindIdentical once. The unique index already expresses the invariant; the code just needs to let the database enforce it.
System Info
Woodpecker v3.18.0 (server + agents), official images, Helm chart 3.7.3, Kubernetes backend, Postgres store, GitHub forge.Additional context
Same behaviour is present on main at the time of writing.
Source: woodpecker-ci/woodpecker