diff --git a/core/src/main/java/hudson/slaves/ChannelPinger.java b/core/src/main/java/hudson/slaves/ChannelPinger.java index ae9efcefd8..49ae7c1cf9 100644 --- a/core/src/main/java/hudson/slaves/ChannelPinger.java +++ b/core/src/main/java/hudson/slaves/ChannelPinger.java @@ -31,6 +31,7 @@ import hudson.model.TaskListener; import hudson.remoting.Channel; import hudson.remoting.PingThread; import jenkins.security.MasterToSlaveCallable; +import jenkins.slaves.PingFailureAnalyzer; import java.io.IOException; import java.util.concurrent.atomic.AtomicBoolean; @@ -107,6 +108,9 @@ public class ChannelPinger extends ComputerListener { final PingThread t = new PingThread(channel, interval * 60 * 1000) { protected void onDead(Throwable cause) { try { + for (PingFailureAnalyzer pfa : PingFailureAnalyzer.all()) { + pfa.onPingFailure(channel,cause); + } if (isInClosed.get()) { LOGGER.log(FINE,"Ping failed after the channel "+channel.getName()+" is already partially closed.",cause); } else { diff --git a/core/src/main/java/hudson/slaves/SlaveComputer.java b/core/src/main/java/hudson/slaves/SlaveComputer.java index c631903705..0a28b2064d 100644 --- a/core/src/main/java/hudson/slaves/SlaveComputer.java +++ b/core/src/main/java/hudson/slaves/SlaveComputer.java @@ -450,6 +450,8 @@ public class SlaveComputer extends Computer { final TaskListener taskListener = new StreamTaskListener(launchLog); PrintStream log = taskListener.getLogger(); + channel.setProperty(SlaveComputer.class, this); + channel.addListener(new Channel.Listener() { @Override public void onClosed(Channel c, IOException cause) { diff --git a/core/src/main/java/jenkins/slaves/PingFailureAnalyzer.java b/core/src/main/java/jenkins/slaves/PingFailureAnalyzer.java new file mode 100644 index 0000000000..aec9d8170b --- /dev/null +++ b/core/src/main/java/jenkins/slaves/PingFailureAnalyzer.java @@ -0,0 +1,33 @@ +package jenkins.slaves; + +import hudson.ExtensionList; +import hudson.ExtensionPoint; +import hudson.remoting.Channel; +import jenkins.model.Jenkins; + +import java.io.IOException; + +/** + * Get notified when a channel triggered a ping failure, but before the channel is killed. + * + *
+ * This provides the opportunity to perform diagnostic activities.
+ *
+ * @author Kohsuke Kawaguchi
+ * @since 1.592
+ */
+public abstract class PingFailureAnalyzer implements ExtensionPoint {
+ /**
+ *
+ * @param c
+ * The channel that caused the ping failure. Because this channel is in a troubled state,
+ * do not attempt a remote call on this channel. Doing so would risk creating a hang.
+ * @param cause
+ * Cause of the ping failure. Informational, and probably uninteresting to most callees.
+ */
+ public abstract void onPingFailure(Channel c, Throwable cause) throws IOException;
+
+ public static ExtensionList