Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-39835] - Be extra defensive about Errors and Exceptions #133

Merged
merged 1 commit into from
Dec 22, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,19 @@ public void ready(boolean accept, boolean connect, boolean read, boolean write)
}
recvKey.cancel();
onRecvClosed();
} catch (RuntimeException e) {
} catch (Throwable t) {
// 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()});
try {
if (LOGGER.isLoggable(Level.SEVERE)) {
LogRecord record = new LogRecord(Level.SEVERE, "[{0}] Uncaught {1}");
record.setThrown(t);
record.setParameters(new Object[]{stack().name(), t.getClass().getSimpleName()});
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole block could be written more simply as

LOGGER.log(Level.SEVERE, "Uncaught error in " + stack().name(), t);

without any real loss.

} finally {
// incase this was an OOMErr and logging caused another OOMErr
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Easier and probably safer to set a boolean flag at the top of the method indicating whether it completed normally; wrap everything in a try-finally block that closes the channel if not.

recvKey.cancel();
onRecvClosed();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this code should rethrow errors afterwards

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was not doing it before the change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was not catching Errors before the change

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it does that you could kill the thread / leave the system in a bad state.

}
recvKey.cancel();
onRecvClosed();
} finally {
release(recv);
}
Expand Down