From 91c1dc578eba70417b05ef0edd961f0717e10c43 Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Fri, 18 Jan 2019 19:15:00 +0900 Subject: Fix runner eternal loop when update job result Add spec Add changelog --- app/models/ci/build.rb | 9 ++++++++- .../fix-runner-eternal-loop-when-update-job-result.yml | 5 +++++ spec/models/ci/build_spec.rb | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/fix-runner-eternal-loop-when-update-job-result.yml diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index dc6f8ae1a7f..cfdb3c0d719 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -224,8 +224,15 @@ module Ci before_transition any => [:failed] do |build| next unless build.project + next unless build.deployment - build.deployment&.drop + begin + build.deployment.drop! + rescue => e + Gitlab::Sentry.track_exception(e, extra: { build_id: build.id }) + end + + true end after_transition any => [:failed] do |build| diff --git a/changelogs/unreleased/fix-runner-eternal-loop-when-update-job-result.yml b/changelogs/unreleased/fix-runner-eternal-loop-when-update-job-result.yml new file mode 100644 index 00000000000..5a6c36e6f5f --- /dev/null +++ b/changelogs/unreleased/fix-runner-eternal-loop-when-update-job-result.yml @@ -0,0 +1,5 @@ +--- +title: Fix runner eternal loop when update job result +merge_request: 24481 +author: +type: fixed diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 1afc2436bb5..60d89313f07 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -3028,6 +3028,24 @@ describe Ci::Build do subject.drop! end end + + context 'when associated deployment failed to update its status' do + let(:build) { create(:ci_build, :running, pipeline: pipeline) } + let!(:deployment) { create(:deployment, deployable: build) } + + before do + allow_any_instance_of(Deployment) + .to receive(:drop!).and_raise('Unexpected error') + end + + it 'can drop the build' do + expect(Gitlab::Sentry).to receive(:track_exception) + + expect { build.drop! }.not_to raise_error + + expect(build).to be_failed + end + end end describe '.matches_tag_ids' do -- cgit v1.2.1