diff --git a/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowRun.java b/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowRun.java index d0bd8eec..fe6d2a7a 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowRun.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowRun.java @@ -691,9 +691,19 @@ private String key() { @Override protected void onLoad() { try { synchronized (getLogCopyGuard()) { // CHECKME: Deadlock risks here - copyLogGuard and locks on Run - boolean completedStateNotPersisted = completed == null; + if (executionLoaded) { + LOGGER.log(Level.WARNING, "Double onLoad of build "+this); + return; + } + boolean needsToPersist = completed == null; super.onLoad(); + if (completed == Boolean.TRUE && result == null) { + LOGGER.log(Level.FINE, "Completed build with no result set, defaulting to failure for"+this); + setResult(Result.FAILURE); + needsToPersist = true; + } + // TODO See if we can simplify this, especially around interactions with 'completed'. if (execution != null && completed != Boolean.TRUE) { @@ -720,7 +730,7 @@ private String key() { } else if (execution == null) { completed = Boolean.TRUE; } - if (completedStateNotPersisted && completed) { + if (needsToPersist && completed) { try { save(); } catch (Exception ex) {