Skip to content

Commit

Permalink
[FIXED JENKINS-26411] Improve error reporting when channel closed
Browse files Browse the repository at this point in the history
  • Loading branch information
olivergondza committed Jan 15, 2015
1 parent f61f2cd commit 788d6ff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
27 changes: 10 additions & 17 deletions core/src/main/java/hudson/model/AbstractBuild.java
Expand Up @@ -38,6 +38,7 @@
import hudson.model.labels.LabelAtom;
import hudson.model.listeners.RunListener;
import hudson.model.listeners.SCMListener;
import hudson.remoting.RequestAbortedException;
import hudson.scm.ChangeLogParser;
import hudson.scm.ChangeLogSet;
import hudson.scm.ChangeLogSet.Entry;
Expand All @@ -47,6 +48,7 @@
import hudson.slaves.NodeProperty;
import hudson.slaves.WorkspaceList;
import hudson.slaves.WorkspaceList.Lease;
import hudson.slaves.OfflineCause;
import hudson.tasks.BuildStep;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.BuildTrigger;
Expand Down Expand Up @@ -537,23 +539,6 @@ public Result run(@Nonnull BuildListener listener) throws Exception {
// use multiple environment variables so that people can escape this massacre by overriding an environment
// variable for some processes
launcher.kill(getCharacteristicEnvVars());
} else {
// As can be seen in HUDSON-5073, when a build fails because of the slave connectivity problem,
// error message doesn't point users to the slave. So let's do it here.
listener.hyperlink("/computer/"+builtOn+"/log","Looks like the node went offline during the build. Check the slave log for the details.");

// TODO: Offline cause seems more reliable here. Plus, this misses permission check log.jelly does.
Computer c = node.toComputer();
if (c != null) {
// grab the end of the log file. This might not work very well if the slave already
// starts reconnecting. Fixing this requires a ring buffer in slave logs.
AnnotatedLargeText<Computer> log = c.getLogText();
StringWriter w = new StringWriter();
log.writeHtmlTo(Math.max(0,c.getLogFile().length()-10240),w);

listener.getLogger().print(ExpandableDetailsNote.encodeTo("details",w.toString()));
listener.getLogger().println();
}
}

// this is ugly, but for historical reason, if non-null value is returned
Expand Down Expand Up @@ -771,7 +756,15 @@ protected final boolean perform(BuildStep bs, BuildListener listener) throws Int

boolean canContinue = false;
try {

canContinue = mon.perform(bs, AbstractBuild.this, launcher, listener);
} catch (RequestAbortedException ex) {
// Channel is closed, do not continue
listener.error("Slave went offline during the build.");
final OfflineCause offlineCause = getCurrentNode().toComputer().getOfflineCause();
if (offlineCause != null) {
listener.error(offlineCause.toString());
}
} catch (RuntimeException ex) {

ex.printStackTrace(listener.error("Build step failed with exception"));
Expand Down
2 changes: 2 additions & 0 deletions test/src/test/java/hudson/model/ExecutorTest.java
Expand Up @@ -141,6 +141,8 @@ public void disconnectCause() throws Exception {
assertEquals(b.getResult(), Result.FAILURE);
assertThat(log, containsString("Finished: FAILURE"));
assertThat(log, containsString("Build step 'Bogus' marked build as failure"));
assertThat(log, containsString("Slave went offline during the build"));
assertThat(log, containsString("Disconnected by Johnny : Taking offline to break your buil"));
}

private Future<FreeStyleBuild> startBlockingBuild(FreeStyleProject p) throws Exception {
Expand Down

0 comments on commit 788d6ff

Please sign in to comment.