Skip to content

Commit

Permalink
[JENKINS-26411] Handle ChannelClosedException as well
Browse files Browse the repository at this point in the history
  • Loading branch information
olivergondza committed Jan 16, 2015
1 parent b0351d2 commit 555e2d5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
22 changes: 15 additions & 7 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.ChannelClosedException;
import hudson.remoting.RequestAbortedException;
import hudson.scm.ChangeLogParser;
import hudson.scm.ChangeLogSet;
Expand Down Expand Up @@ -760,13 +761,10 @@ protected final boolean perform(BuildStep bs, BuildListener listener) throws Int
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"));
Expand All @@ -787,6 +785,16 @@ protected final boolean perform(BuildStep bs, BuildListener listener) throws Int
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();
Expand Down
6 changes: 5 additions & 1 deletion test/src/test/java/hudson/model/ExecutorTest.java
Expand Up @@ -6,6 +6,7 @@
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;
Expand Down Expand Up @@ -166,10 +167,13 @@ private BlockingBuilder(OneShotEvent e) {

@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);
}
}
Expand Down

0 comments on commit 555e2d5

Please sign in to comment.