From a4ab9759ea614d9807ccf3476ca958f72b4db3c1 Mon Sep 17 00:00:00 2001
From: Robert Speicher <robert@gitlab.com>
Date: Wed, 31 Aug 2016 15:56:48 +0000
Subject: [PATCH] Merge branch 'block-concurrent-pipeline-processings' into
 'master'

Block concurrent pipeline processings

## What does this MR do?

It's possible that two builds that succeed at the same will try to
concurrently process pipeline. This can lead to scenario when it will
fail to trigger next stages.

This MR makes sure that process of updating is blocking.

Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/21263

See merge request !6090
---
 CHANGELOG                                   |  5 +++++
 app/services/ci/process_pipeline_service.rb | 14 ++++++++------
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 1779d52c3d..2d1999315c 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -9,6 +9,11 @@ v 8.11.4
   - Do not enforce using hash with hidden key in CI configuration. !6079
   - Fix hover leading space bug in pipeline graph !5980
   - Do not enforce using hash with hidden key in CI configuration. !6079
+  - Creating an issue through our API now emails label subscribers !5720
+  - Block concurrent updates for Pipeline
+  - Fix resolving conflicts on forks
+  - Fix diff commenting on merge requests created prior to 8.10
+  - Fix issue boards leak private label names and descriptions
 
 v 8.11.3
   - Don't show resolve conflicts link before MR status is updated
diff --git a/app/services/ci/process_pipeline_service.rb b/app/services/ci/process_pipeline_service.rb
index 6f7610d42b..e38709853c 100644
--- a/app/services/ci/process_pipeline_service.rb
+++ b/app/services/ci/process_pipeline_service.rb
@@ -10,13 +10,15 @@ module Ci
         create_builds!
       end
 
-      new_builds =
-        stage_indexes_of_created_builds.map do |index|
-          process_stage(index)
-        end
+      @pipeline.with_lock do
+        new_builds =
+          stage_indexes_of_created_builds.map do |index|
+            process_stage(index)
+          end
 
-      # Return a flag if a when builds got enqueued
-      new_builds.flatten.any?
+        # Return a flag if a when builds got enqueued
+        new_builds.flatten.any?
+      end
     end
 
     private
-- 
2.30.9