From f1fbf8c6055771e42bb2e175aa49286dc9d3547a Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 7 Aug 2015 04:18:48 +0200 Subject: [PATCH] Fix race in finishing builds that have been cancelled --- src/hydra-queue-runner/hydra-queue-runner.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/hydra-queue-runner/hydra-queue-runner.cc b/src/hydra-queue-runner/hydra-queue-runner.cc index 10fd1cd1..22de76ae 100644 --- a/src/hydra-queue-runner/hydra-queue-runner.cc +++ b/src/hydra-queue-runner/hydra-queue-runner.cc @@ -211,6 +211,8 @@ void State::markSucceededBuild(pqxx::work & txn, Build::ptr build, if (build->finishedInDB) return; + if (txn.parameterized("select 1 from Builds where id = $1 and finished = 0")(build->id).exec().empty()) return; + txn.parameterized ("update Builds set finished = 1, busy = 0, buildStatus = $2, startTime = $3, stopTime = $4, size = $5, closureSize = $6, releaseName = $7, isCachedBuild = $8 where id = $1 and finished = 0") (build->id) @@ -222,6 +224,8 @@ void State::markSucceededBuild(pqxx::work & txn, Build::ptr build, (res.releaseName, res.releaseName != "") (isCachedBuild ? 1 : 0).exec(); + txn.parameterized("delete from BuildProducts where build = $1")(build->id).exec(); + unsigned int productNr = 1; for (auto & product : res.products) { txn.parameterized @@ -238,6 +242,8 @@ void State::markSucceededBuild(pqxx::work & txn, Build::ptr build, (product.defaultPath).exec(); } + txn.parameterized("delete from BuildMetrics where build = $1")(build->id).exec(); + for (auto & metric : res.metrics) { txn.parameterized ("insert into BuildMetrics (build, name, unit, value, project, jobset, job, timestamp) values ($1, $2, $3, $4, $5, $6, $7, $8)")