Skip to content

Commit

Permalink
[JENKINS-22722] - Make AsynchronousCommandTransport tolerant against …
Browse files Browse the repository at this point in the history
…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 25373d7
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/main/java/hudson/remoting/SynchronousCommandTransport.java
Expand Up @@ -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;

Expand All @@ -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.
*/
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 25373d7

Please sign in to comment.