Skip to content

Commit db1bc7f

Browse files
author
epriestley
committed
Carefully avoid the harbormaster/differential race
Summary: Ref T8650. This should stop the problem, but isn't a root cause fix. See discussion on the task. Test Plan: Made some local diffs, but this is a bit hard to reproduce reliably. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T8650 Differential Revision: https://secure.phabricator.com/D13441
1 parent 5f99d79 commit db1bc7f

File tree

2 files changed

+56
-36
lines changed

2 files changed

+56
-36
lines changed

src/applications/differential/editor/DifferentialTransactionEditor.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,8 @@ protected function applyCustomExternalTransaction(
585585
'a race?'));
586586
}
587587

588+
// TODO: This can race with diff updates, particularly those from
589+
// Harbormaster. See discussion in T8650.
588590
$diff->setRevisionID($object->getID());
589591
$diff->save();
590592

@@ -593,6 +595,8 @@ protected function applyCustomExternalTransaction(
593595
// the old (`null`) container.
594596

595597
// TODO: This is a bit iffy, maybe we can find a cleaner approach?
598+
// In particular, this could (rarely) be overwritten by Harbormaster
599+
// workers.
596600
$table = new HarbormasterBuildable();
597601
$conn_w = $table->establishConnection('w');
598602
queryfx(

src/applications/harbormaster/engine/HarbormasterBuildEngine.php

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -406,43 +406,59 @@ private function updateBuildable(HarbormasterBuildable $buildable) {
406406
$should_publish = $did_update &&
407407
$new_status != HarbormasterBuildable::STATUS_BUILDING &&
408408
!$buildable->getIsManualBuildable();
409-
if ($should_publish) {
410-
$object = id(new PhabricatorObjectQuery())
411-
->setViewer($viewer)
412-
->withPHIDs(array($buildable->getBuildablePHID()))
413-
->executeOne();
414-
415-
if ($object instanceof PhabricatorApplicationTransactionInterface) {
416-
$template = $object->getApplicationTransactionTemplate();
417-
if ($template) {
418-
$template
419-
->setTransactionType(PhabricatorTransactions::TYPE_BUILDABLE)
420-
->setMetadataValue(
421-
'harbormaster:buildablePHID',
422-
$buildable->getPHID())
423-
->setOldValue($old_status)
424-
->setNewValue($new_status);
425-
426-
$harbormaster_phid = id(new PhabricatorHarbormasterApplication())
427-
->getPHID();
428-
429-
$daemon_source = PhabricatorContentSource::newForSource(
430-
PhabricatorContentSource::SOURCE_DAEMON,
431-
array());
432-
433-
$editor = $object->getApplicationTransactionEditor()
434-
->setActor($viewer)
435-
->setActingAsPHID($harbormaster_phid)
436-
->setContentSource($daemon_source)
437-
->setContinueOnNoEffect(true)
438-
->setContinueOnMissingFields(true);
439-
440-
$editor->applyTransactions(
441-
$object->getApplicationTransactionObject(),
442-
array($template));
443-
}
444-
}
409+
410+
if (!$should_publish) {
411+
return;
412+
}
413+
414+
$object = id(new PhabricatorObjectQuery())
415+
->setViewer($viewer)
416+
->withPHIDs(array($buildable->getBuildablePHID()))
417+
->executeOne();
418+
if (!$object) {
419+
return;
445420
}
421+
422+
if (!($object instanceof PhabricatorApplicationTransactionInterface)) {
423+
return;
424+
}
425+
426+
// TODO: Publishing these transactions is causing a race. See T8650.
427+
// We shouldn't be publishing to diffs anyway.
428+
if ($object instanceof DifferentialDiff) {
429+
return;
430+
}
431+
432+
$template = $object->getApplicationTransactionTemplate();
433+
if (!$template) {
434+
return;
435+
}
436+
437+
$template
438+
->setTransactionType(PhabricatorTransactions::TYPE_BUILDABLE)
439+
->setMetadataValue(
440+
'harbormaster:buildablePHID',
441+
$buildable->getPHID())
442+
->setOldValue($old_status)
443+
->setNewValue($new_status);
444+
445+
$harbormaster_phid = id(new PhabricatorHarbormasterApplication())
446+
->getPHID();
447+
448+
$daemon_source = PhabricatorContentSource::newForSource(
449+
PhabricatorContentSource::SOURCE_DAEMON,
450+
array());
451+
452+
$editor = $object->getApplicationTransactionEditor()
453+
->setActor($viewer)
454+
->setActingAsPHID($harbormaster_phid)
455+
->setContentSource($daemon_source)
456+
->setContinueOnNoEffect(true)
457+
->setContinueOnMissingFields(true);
458+
459+
$editor->applyTransactions(
460+
$object->getApplicationTransactionObject(),
461+
array($template));
446462
}
447463

448464
private function releaseAllArtifacts(HarbormasterBuild $build) {

0 commit comments

Comments
 (0)