Skip to content
Permalink
Browse files

[JENKINS-22722] - Make AsynchronousCommandTransport tolerant against …

…Socket timeouts (#86)

* [JENKINS-22722] - Make AsynchronousCommandTransport tolerant against Socket timeouts

* [JENKINS-22722] - Fix the formatting
  • Loading branch information...
oleg-nenashev committed Jun 9, 2016
1 parent a1bdc23 commit 25373d73e7369e9e8e21e2308f7051d5d1e9a16c
Showing with 23 additions and 0 deletions.
  1. +23 −0 src/main/java/hudson/remoting/SynchronousCommandTransport.java
@@ -3,6 +3,7 @@
import java.io.EOFException;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.SocketTimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;

@@ -17,6 +18,16 @@
public abstract class SynchronousCommandTransport extends CommandTransport {
protected Channel channel;

private static final String RDR_SOCKET_TIMEOUT_PROPERTY_NAME =
SynchronousCommandTransport.class.getName() + ".failOnSocketTimeoutInReader";

/**
* Enables the original aggressive behavior, when the channel reader gets
* interrupted on any {@link SocketTimeoutException}.
* @since TODO
*/
private static boolean RDR_FAIL_ON_SOCKET_TIMEOUT = Boolean.getBoolean(RDR_SOCKET_TIMEOUT_PROPERTY_NAME);

/**
* Called by {@link Channel} to read the next command to arrive from the stream.
*/
@@ -46,6 +57,18 @@ public void run() {
Command cmd = null;
try {
cmd = read();
} catch (SocketTimeoutException ex) {
if (RDR_FAIL_ON_SOCKET_TIMEOUT) {
LOGGER.log(Level.SEVERE, "Socket timeout in the Synchronous channel reader."
+ " The channel will be interrupted, because " + RDR_SOCKET_TIMEOUT_PROPERTY_NAME
+ " is set", ex);
throw ex;
}
// Timeout happened during the read operation.
// It is not always fatal, because it may be caused by a long-running command
// If channel is not closed, it's OK to continue reading the channel
LOGGER.log(Level.WARNING, "Socket timeout in the Synchronous channel reader", ex);
continue;
} catch (EOFException e) {
IOException ioe = new IOException("Unexpected termination of the channel");
ioe.initCause(e);

0 comments on commit 25373d7

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