diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2017-06-01 20:36:59 +0000 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2017-06-01 20:36:59 +0000 |
commit | b92e3d746466667642fd99d1ed72b481488d1a9f (patch) | |
tree | 4ea61086bbb5166fb7d3ff946ac18287913dd49a /app | |
parent | 1cd5c6d940baf5ee03e14ab924c4bb198aa04fd7 (diff) | |
parent | 94be44c568b0167bbcc1e975ab674747a8271dbc (diff) | |
download | gitlab-ce-b92e3d746466667642fd99d1ed72b481488d1a9f.tar.gz |
Merge branch 'dm-fix-pipeline-creation-race-condition' into 'master'
Fix race condition between pipeline creation and MR diff_head_sha update
Closes #33219
See merge request !11859
Diffstat (limited to 'app')
-rw-r--r-- | app/services/ci/create_pipeline_service.rb | 9 | ||||
-rw-r--r-- | app/services/merge_requests/create_service.rb | 9 |
2 files changed, 6 insertions, 12 deletions
diff --git a/app/services/ci/create_pipeline_service.rb b/app/services/ci/create_pipeline_service.rb index 8227a78a650..13baa63220d 100644 --- a/app/services/ci/create_pipeline_service.rb +++ b/app/services/ci/create_pipeline_service.rb @@ -63,13 +63,10 @@ module Ci private def update_merge_requests_head_pipeline - merge_requests = MergeRequest.where(source_branch: @pipeline.ref, source_project: @pipeline.project) + return unless pipeline.latest? - merge_requests = merge_requests.select do |mr| - mr.diff_head_sha == @pipeline.sha - end - - MergeRequest.where(id: merge_requests).update_all(head_pipeline_id: @pipeline.id) + MergeRequest.where(source_project: @pipeline.project, source_branch: @pipeline.ref). + update_all(head_pipeline_id: @pipeline.id) end def skip_ci? diff --git a/app/services/merge_requests/create_service.rb b/app/services/merge_requests/create_service.rb index fbf171f705e..71d37797bb4 100644 --- a/app/services/merge_requests/create_service.rb +++ b/app/services/merge_requests/create_service.rb @@ -30,15 +30,12 @@ module MergeRequests def head_pipeline_for(merge_request) return unless merge_request.source_project - sha = merge_request.source_branch_head&.id - + sha = merge_request.source_branch_sha return unless sha - pipelines = - Ci::Pipeline.where(ref: merge_request.source_branch, project_id: merge_request.source_project.id, sha: sha). - order(id: :desc) + pipelines = merge_request.source_project.pipelines.where(ref: merge_request.source_branch, sha: sha) - pipelines.first + pipelines.order(id: :desc).first end end end |