From 555e2d593fbb419d2fad7e9cfae5911daf3d30e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20Gond=C5=BEa?= Date: Fri, 16 Jan 2015 11:17:50 +0100 Subject: [PATCH] [JENKINS-26411] Handle ChannelClosedException as well --- .../main/java/hudson/model/AbstractBuild.java | 22 +++++++++++++------ .../test/java/hudson/model/ExecutorTest.java | 6 ++++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/hudson/model/AbstractBuild.java b/core/src/main/java/hudson/model/AbstractBuild.java index a44066da95..d6dc13703f 100644 --- a/core/src/main/java/hudson/model/AbstractBuild.java +++ b/core/src/main/java/hudson/model/AbstractBuild.java @@ -38,6 +38,7 @@ import hudson.model.Fingerprint.RangeSet; import hudson.model.labels.LabelAtom; import hudson.model.listeners.RunListener; import hudson.model.listeners.SCMListener; +import hudson.remoting.ChannelClosedException; import hudson.remoting.RequestAbortedException; import hudson.scm.ChangeLogParser; import hudson.scm.ChangeLogSet; @@ -760,13 +761,10 @@ public abstract class AbstractBuild

,R extends Abs canContinue = mon.perform(bs, AbstractBuild.this, launcher, listener); } catch (RequestAbortedException ex) { // Channel is closed, do not continue - final Node node = getCurrentNode(); - listener.hyperlink("/" + node.toComputer().getUrl() + "log", "Slave went offline during the build"); - listener.getLogger().println(); - final OfflineCause offlineCause = node.toComputer().getOfflineCause(); - if (offlineCause != null) { - listener.error(offlineCause.toString()); - } + reportBrokenChannel(listener); + } catch (ChannelClosedException ex) { + // Channel is closed, do not continue + reportBrokenChannel(listener); } catch (RuntimeException ex) { ex.printStackTrace(listener.error("Build step failed with exception")); @@ -787,6 +785,16 @@ public abstract class AbstractBuild

,R extends Abs return canContinue; } + private void reportBrokenChannel(BuildListener listener) throws IOException { + final Node node = getCurrentNode(); + listener.hyperlink("/" + node.toComputer().getUrl() + "log", "Slave went offline during the build"); + listener.getLogger().println(); + final OfflineCause offlineCause = node.toComputer().getOfflineCause(); + if (offlineCause != null) { + listener.error(offlineCause.toString()); + } + } + private String getBuildStepName(BuildStep bs) { if (bs instanceof Describable) { return ((Describable) bs).getDescriptor().getDisplayName(); diff --git a/test/src/test/java/hudson/model/ExecutorTest.java b/test/src/test/java/hudson/model/ExecutorTest.java index 6c46992429..9259377242 100644 --- a/test/src/test/java/hudson/model/ExecutorTest.java +++ b/test/src/test/java/hudson/model/ExecutorTest.java @@ -6,6 +6,7 @@ import static org.junit.Assert.*; import com.gargoylesoftware.htmlunit.html.HtmlPage; import hudson.Launcher; +import hudson.remoting.VirtualChannel; import hudson.slaves.DumbSlave; import hudson.slaves.OfflineCause; import hudson.util.OneShotEvent; @@ -166,10 +167,13 @@ public class ExecutorTest { @Override public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { + VirtualChannel channel = launcher.getChannel(); + Node node = build.getBuiltOn(); + e.signal(); // we are safe to be interrupted for (;;) { // Keep using the channel - build.getBuiltOn().getClockDifference(); + channel.call(node.getClockDifferenceCallable()); Thread.sleep(100); } }