Skip to content
Permalink
Browse files

Merge pull request #85 from jglick/PingThread-JENKINS-35190

[JENKINS-35190] PingThread fixes
  • Loading branch information
jglick committed May 31, 2016
2 parents c0cf331 + 7ff0a9a commit 59e33a4a6592bdf9c6dddd80fbeeaf4cc679a2a2
Showing with 15 additions and 1 deletion.
  1. +11 −1 src/main/java/hudson/remoting/Launcher.java
  2. +4 −0 src/main/java/hudson/remoting/PingThread.java
@@ -76,6 +76,8 @@
import java.security.KeyManagementException;
import java.security.SecureRandom;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

@@ -521,14 +523,22 @@ public static void main(InputStream is, OutputStream os, Mode mode, boolean perf
long timeout = 1000 * Long.parseLong(
System.getProperty("hudson.remoting.Launcher.pingTimeoutSec", "240")),
interval = 1000 * Long.parseLong(
System.getProperty("hudson.remoting.Launcher.pingIntervalSec", "600"));
System.getProperty("hudson.remoting.Launcher.pingIntervalSec", /* was "600" but this duplicates ChannelPinger */ "0"));
Logger.getLogger(PingThread.class.getName()).log(Level.FINE, "performPing={0} timeout={1} interval={2}", new Object[] {performPing, timeout, interval});
if (performPing && timeout > 0 && interval > 0) {
new PingThread(channel, timeout, interval) {
@Deprecated
@Override
protected void onDead() {
System.err.println("Ping failed. Terminating");
System.exit(-1);
}
@Override
protected void onDead(Throwable cause) {
System.err.println("Ping failed. Terminating");
cause.printStackTrace();
System.exit(-1);
}
}.start();
}
channel.join();
@@ -32,6 +32,7 @@
import java.util.logging.Logger;

import static java.util.concurrent.TimeUnit.MILLISECONDS;
import java.util.logging.Level;

/**
* Periodically perform a ping.
@@ -101,15 +102,18 @@ public void run() {
}

private void ping() throws IOException, InterruptedException {
LOGGER.log(Level.FINE, "pinging {0}", channel.getName());
Future<?> f = channel.callAsync(new Ping());
long start = System.currentTimeMillis();

long end = System.nanoTime() + TimeUnit.MILLISECONDS.toNanos(timeout);
long remaining = end - System.nanoTime();

do {
LOGGER.log(Level.FINE, "waiting {0}s on {1}", new Object[] {TimeUnit.NANOSECONDS.toSeconds(remaining), channel.getName()});
try {
f.get(Math.max(1,remaining),TimeUnit.NANOSECONDS);
LOGGER.log(Level.FINE, "ping succeeded on {0}", channel.getName());
return;
} catch (ExecutionException e) {
if (e.getCause() instanceof RequestAbortedException)

0 comments on commit 59e33a4

Please sign in to comment.
You can’t perform that action at this time.