Avoid multiple invocations of afterConnectionClosed

This change ensures the state of a SockJS session is set to CLOSED
immediately after close is invoked. This avoids duplicate invocations
of afterConnectionClosed in WebSocket transport.

This is a backport of:
3af488a701

Issue: SPR-11884
This commit is contained in:
Rossen Stoyanchev
2014-06-29 16:53:21 -04:00
parent 618771d59d
commit d18fc53148

View File

@@ -274,6 +274,7 @@ public abstract class AbstractSockJsSession implements SockJsSession {
if (logger.isDebugEnabled()) {
logger.debug("Closing " + this + ", " + status);
}
this.state = State.CLOSED;
try {
if (isActive() && !CloseStatus.SESSION_NOT_RELIABLE.equals(status)) {
try {
@@ -289,7 +290,6 @@ public abstract class AbstractSockJsSession implements SockJsSession {
disconnect(status);
}
finally {
this.state = State.CLOSED;
try {
this.handler.afterConnectionClosed(this, status);
}
@@ -339,11 +339,17 @@ public abstract class AbstractSockJsSession implements SockJsSession {
catch (Throwable ex) {
logWriteFrameFailure(ex);
try {
// Force disconnect (so we won't try to send close frame)
disconnect(CloseStatus.SERVER_ERROR);
}
catch (Throwable disconnectFailure) {
logger.error("Failure while closing " + this, disconnectFailure);
}
try {
close(CloseStatus.SERVER_ERROR);
}
catch (Throwable ex2) {
// ignore
catch (Throwable t) {
// Nothing of consequence, already forced disconnect
}
throw new SockJsTransportFailureException("Failed to write " + frame, this.getId(), ex);
}