Fix exclusive lease usage in transaction for app/services/ci/retry_job_service.rb

See original issue in #440368 (closed).

Call site: https://gitlab.com/gitlab-org/gitlab/-/blob/ea71b210ca72ab6a061ffb3df09ed03b50e231c8/app/services/ci/retry_job_service.rb#L50

Problem

The problem happens because the after_transition hook, runs in the context of a transaction, then, the flow runs in the following order (see here for more):

  • RetryJobService is called
  • Then the AddJobService is called and tries to acquire a lock within the initial transaction which started in the after_transition hook.

Implementation Details

  • Use the run_after_commit hook described here
Edited by Panos Kanellidis