Commit 348d5bdc authored by Tom Evans's avatar Tom Evans

OF-857: Synchronize connection/session cleanup

This patch is to prevent a stack overflow in certain exception cases
where a connection has been closed, but its corresponding session is
still present in the routing table.
parent 111fe941
...@@ -203,9 +203,10 @@ public class NIOConnection implements Connection { ...@@ -203,9 +203,10 @@ public class NIOConnection implements Connection {
} }
public void close() { public void close() {
boolean closedSuccessfully = false; synchronized(this) {
synchronized (this) { if (isClosed()) {
if (!isClosed()) { return;
}
try { try {
deliverRawText(flashClient ? "</flash:stream>" : "</stream:stream>", false); deliverRawText(flashClient ? "</flash:stream>" : "</stream:stream>", false);
} catch (Exception e) { } catch (Exception e) {
...@@ -214,14 +215,10 @@ public class NIOConnection implements Connection { ...@@ -214,14 +215,10 @@ public class NIOConnection implements Connection {
if (session != null) { if (session != null) {
session.setStatus(Session.STATUS_CLOSED); session.setStatus(Session.STATUS_CLOSED);
} }
ioSession.close(false); notifyCloseListeners(); // clean up session, etc.
closed = true; closed = true;
closedSuccessfully = true;
}
}
if (closedSuccessfully) {
notifyCloseListeners();
} }
ioSession.close(false); // async via MINA
} }
public void systemShutdown() { public void systemShutdown() {
...@@ -248,12 +245,9 @@ public class NIOConnection implements Connection { ...@@ -248,12 +245,9 @@ public class NIOConnection implements Connection {
session = owner; session = owner;
} }
public boolean isClosed() { public synchronized boolean isClosed() {
if (session == null) {
return closed; return closed;
} }
return session.getStatus() == Session.STATUS_CLOSED;
}
public boolean isSecure() { public boolean isSecure() {
return ioSession.getFilterChain().contains(TLS_FILTER_NAME); return ioSession.getFilterChain().contains(TLS_FILTER_NAME);
......
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