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

OF-883: Compensate for new half-duplex close of TCP channel in MINA

MINA 2.0.8 introduces support for half-duplex close of TCP channels (see DIRMINA-785).
As part of this change, IoHandlers got a new method. The default behavior of the
IoHandlerAdapter closes the MINA session when this handler is triggered. However,
without an Openfire-specific extension (in ConnectionHandler), this fails to close
Openfire-maintained resources. As a result, CPUs could start to spin in NIO code,
resulting in 100% CPU cycles.

To fix this issue, ConnectionHandler now overrides the default functionality and
triggers a normal closure of the session (both in Openfire as well as MINA context).

Additionally, to prevent the CPU spin, MINA sessions need to be closed synchronously
(as opposed to the async closure Openfire had up until now). I cannot quite explain
the need for this change, other than a suspision of race conditions in the async
setup.
parent bc19c579
...@@ -107,6 +107,14 @@ public abstract class ConnectionHandler extends IoHandlerAdapter { ...@@ -107,6 +107,14 @@ public abstract class ConnectionHandler extends IoHandlerAdapter {
} }
} }
@Override
public void inputClosed( IoSession session ) throws Exception {
// Get the connection for this session
Connection connection = (Connection) session.getAttribute(CONNECTION);
// Inform the connection that it was closed
connection.close();
}
@Override @Override
public void sessionClosed(IoSession session) throws Exception { public void sessionClosed(IoSession session) throws Exception {
// Get the connection for this session // Get the connection for this session
......
...@@ -222,7 +222,7 @@ public class NIOConnection implements Connection { ...@@ -222,7 +222,7 @@ public class NIOConnection implements Connection {
return; return;
} }
try { try {
deliverRawText(flashClient ? "</flash:stream>" : "</stream:stream>", false); deliverRawText(flashClient ? "</flash:stream>" : "</stream:stream>", true);
} catch (Exception e) { } catch (Exception e) {
// Ignore // Ignore
} }
...@@ -235,7 +235,7 @@ public class NIOConnection implements Connection { ...@@ -235,7 +235,7 @@ public class NIOConnection implements Connection {
// OF-881: Notify any close listeners after the synchronized block has completed. // OF-881: Notify any close listeners after the synchronized block has completed.
notifyCloseListeners(); // clean up session, etc. notifyCloseListeners(); // clean up session, etc.
ioSession.close(false); // async via MINA ioSession.close(true); // sync via MINA
} }
public void systemShutdown() { public void systemShutdown() {
......
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