Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-38344] Catch uncaught exceptions, log and close connec…
…tion
  • Loading branch information
stephenc committed Sep 19, 2016
1 parent 94e90bb commit a208126
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/main/java/org/jenkinsci/remoting/protocol/IOHub.java
Expand Up @@ -50,6 +50,7 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.AbstractQueuedSynchronizer;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import javax.annotation.Nonnull;
import javax.annotation.OverridingMethodsMustInvokeSuper;
Expand Down Expand Up @@ -693,6 +694,13 @@ public void run() {
(ops & SelectionKey.OP_CONNECT) == SelectionKey.OP_CONNECT,
(ops & SelectionKey.OP_READ) == SelectionKey.OP_READ,
(ops & SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE);
} catch (Throwable e) {
if (LOGGER.isLoggable(Level.SEVERE)) {
LogRecord record = new LogRecord(Level.SEVERE, "[{0}] Listener {1} propagated an uncaught {2}");
record.setThrown(e);
record.setParameters(new Object[]{workerThread.getName(), listener, e.getClass().getSimpleName()});
LOGGER.log(record);
}
} finally {
workerThread.setName(oldName);
}
Expand Down
Expand Up @@ -23,6 +23,7 @@
*/
package org.jenkinsci.remoting.protocol.impl;

import java.util.logging.LogRecord;
import javax.annotation.Nonnull;
import java.io.EOFException;
import java.io.IOException;
Expand Down Expand Up @@ -248,10 +249,23 @@ public void run() {
} catch (ClosedChannelException e) {
onRecvClosed();
return;
} catch (EOFException e) {
} catch (IOException e) {
if (LOGGER.isLoggable(Level.FINER)) {
// will likely be reported elsewhere, so we just trace this at FINER
LogRecord record = new LogRecord(Level.FINER, "[{0}] Unexpected I/O exception");
record.setThrown(e);
record.setParameters(new Object[]{stack().name()});
LOGGER.log(record);
}
onRecvClosed();
return;
} catch (IOException e) {
} catch (RuntimeException e) {
// this should *never* happen... but just in case it does we will log & close connection
if (LOGGER.isLoggable(Level.WARNING)) {
LogRecord record = new LogRecord(Level.WARNING, "[{0}] Uncaught {1}");
record.setThrown(e);
record.setParameters(new Object[]{stack().name(), e.getClass().getSimpleName()});
}
onRecvClosed();
return;
}
Expand All @@ -273,6 +287,13 @@ public void run() {
} finally {
release(buffer);
}
} catch (Throwable e) {
if (LOGGER.isLoggable(Level.SEVERE)) {
LogRecord record = new LogRecord(Level.SEVERE, "[{0}] Reader thread killed by {1}");
record.setThrown(e);
record.setParameters(new Object[]{stack().name(), e.getClass().getSimpleName()});
LOGGER.log(record);
}
} finally {
synchronized (BIONetworkLayer.this) {
running = false;
Expand Down
Expand Up @@ -167,6 +167,15 @@ public void ready(boolean accept, boolean connect, boolean read, boolean write)
}
recvKey.cancel();
onRecvClosed();
} catch (RuntimeException e) {
// this should *never* happen... but just in case it does we will log & close connection
if (LOGGER.isLoggable(Level.WARNING)) {
LogRecord record = new LogRecord(Level.WARNING, "[{0}] Uncaught {1}");
record.setThrown(e);
record.setParameters(new Object[]{stack().name(), e.getClass().getSimpleName()});
}
recvKey.cancel();
onRecvClosed();
}
} else {
onRecvClosed();
Expand Down Expand Up @@ -194,7 +203,14 @@ public void ready(boolean accept, boolean connect, boolean read, boolean write)
} catch (ClosedChannelException e) {
sendKey.cancel();
return;
} catch (final IOException e) {
} catch (IOException e) {
if (LOGGER.isLoggable(Level.FINER)) {
// will be reported elsewhere, so we just trace this at FINER
LogRecord record = new LogRecord(Level.FINER, "[{0}] Unexpected I/O exception");
record.setThrown(e);
record.setParameters(new Object[]{stack().name()});
LOGGER.log(record);
}
sendKey.cancel();
return;
}
Expand Down

0 comments on commit a208126

Please sign in to comment.