Commit bc19c579 authored by Guus der Kinderen's avatar Guus der Kinderen

OF-883: When an exception occurs, make sure the session gets closed.

parent bffe449a
...@@ -145,30 +145,21 @@ public abstract class ConnectionHandler extends IoHandlerAdapter { ...@@ -145,30 +145,21 @@ public abstract class ConnectionHandler extends IoHandlerAdapter {
@Override @Override
public void exceptionCaught(IoSession session, Throwable cause) throws Exception { public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
if (cause instanceof IOException) {
// TODO Verify if there were packets pending to be sent and decide what to do with them
Log.info("ConnectionHandler reports IOException for session: " + session, cause);
if (cause instanceof SSLHandshakeException) {
session.close(true);
}
}
else if (cause instanceof ProtocolDecoderException) {
Log.warn("Closing session due to exception: " + session, cause); Log.warn("Closing session due to exception: " + session, cause);
// PIO-524: Determine stream:error message. try {
// OF-524: Determine stream:error message.
final StreamError error; final StreamError error;
if (cause.getCause() != null && cause.getCause() instanceof XMLNotWellFormedException) { if ( cause != null && (cause instanceof XMLNotWellFormedException || (cause.getCause() != null && cause.getCause() instanceof XMLNotWellFormedException) ) ) {
error = new StreamError(StreamError.Condition.not_well_formed); error = new StreamError( StreamError.Condition.not_well_formed );
} else { } else {
error = new StreamError(StreamError.Condition.internal_server_error); error = new StreamError( StreamError.Condition.internal_server_error );
} }
final Connection connection = (Connection) session.getAttribute(CONNECTION); final Connection connection = (Connection) session.getAttribute( CONNECTION );
connection.deliverRawText(error.toXML()); connection.deliverRawText( error.toXML() );
session.close(true); } finally {
} session.close( false );
else {
Log.error("ConnectionHandler reports unexpected exception for session: " + session, cause);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment