(Incident 19034) Prevent closing of merge requests that are merged
Context
During gitlab-com/gl-infra/production#19034 (closed), we got internal reports of some MRs being closed after they were merged. Also see #510562 (closed).
The state_machines
declaration on the MergeRequest
only allows open
MRs to transition to closed
. But race conditions could happen. For example:
- Sidekiq thread 1 loads the MR and it is open at this point
- Sidekiq thread 2 merges the MR
- Sidekiq thread 1 closes the MR and succeeds because in-memory it is still open
Proposal
- In Slack, we discussed it was suggested that we can add a
WHERE state = open
clause to the update query to prevent this. This does mean that the logic is duplicated between the state machine and the close service query. - Force reading from primary when closing an MR
Edited by 🤖 GitLab Bot 🤖