Skip to content

Handle InvalidForeignKey error within `ensure_metrics`

Adam Hegyi requested to merge 200095-gracefully-handle-create-metrics into master

What does this MR do?

This MR fixes a race condition that could lead to InvalidForeignKey error.

Example:

Merge request is being processed in two different processes (process_1, process_2).

  1. process_2 calls save on an existing MR.
  2. process_1 calls delete on the merge request at the same time.
  3. process_2 starts processing after_save callbacks
  4. process_1 finished deleting the MR.
  5. process_2 has no metrics records (deleted) and it tries to create it (#ensure_metrics)
  6. process_2 fails to create the metrics record since the merge_request record is not there anymore (invalid FK)

I'm setting the ~backstage label because the error mostly occurs within sidekiq.

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Closes #200095 (closed)

Edited by Adam Hegyi

Merge request reports