MR can be merged when latest Merge Request Pipeline fails
Summary
According to our troubleshooting docs for Merge request pipelines, an MR pipeline will fail (and thus prevents merge if that option is enabled) if:
- The branch pipeline succeeds.
- The merge request pipeline fails.
In practice, when both Merge Request-type and Branch-type pipelines are being triggered simultaneously, a race condition will determine which of the two becomes the "primary" pipeline, and whose result determines if the "Merge Request Pipeline" is considered as "failed" or "passed", unlike the definition in our docs.
Steps to reproduce
The example project below (courtesy of the nice folks at Zapier) uses a script with a delay, to simulate the two possible results of a race condition between Merge Request-type
and Branch-type
pipelines:
-
MR!10 is being blocked, as the failed
Branch-type
pipeline was run first, and thus taken as primary -
MR!23 is marked as ready to merge, as the
Merge Request-type
pipeline is run first, taken as primary, and passes as expected.
Example Project
What is the current bug behavior?
We are not deterministic in terms of which pipeline gates MR's from being blocked or not, when Require a successful pipeline for merge has been enabled.
What is the expected correct behavior?
On MR-type
pipelines should gate an MR from being merged or not, independently of race conditions.
Possible workarounds
The best workaround for this is to only merge request pipelines. Documentation for how to avoid duplicate pipelines is here.
Relevant logs and/or screenshots
Blocked MR due to failed pipeline
MR-type
pipeline has passed
Output of checks
This bug happens on GitLab.com
Possible fixes
The problem was in the commit status API, see the fix !147212 (merged). The logic responsible for updating merge_requests.head_pipeline_id
is racy, but the conditions required to incorrectly enable a merge in the way described here are both extremely unlikely to occur, and expensive to fully eliminate. They should be handled in a separate issue if they are found to be a problem.