Improve close in ConcurrentWebSocketSessionDecorator
Before this commit the concurrent session wrapper mainly protected the
sending of messages. The close itself however may also cause a message
to be sent as is the case of the SockJS protocol.
This change protects the close and checks if the session has exceeded
send time or buffer limits in which case the close status is changed
to SESSION_NOT_RELIABLE (introduced in commit cbd5af3a) which in turn
signals that extra care should be exercised when closing the session.
Issue: SPR-13904
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -169,8 +169,31 @@ public class ConcurrentWebSocketSessionDecorator extends WebSocketSessionDecorat
|
||||
|
||||
@Override
|
||||
public void close(CloseStatus status) throws IOException {
|
||||
this.shutdownInProgress = true;
|
||||
super.close(status);
|
||||
this.closeLock.lock();
|
||||
try {
|
||||
if (this.shutdownInProgress) {
|
||||
return;
|
||||
}
|
||||
if (!CloseStatus.SESSION_NOT_RELIABLE.equals(status)) {
|
||||
try {
|
||||
checkSessionLimits();
|
||||
}
|
||||
catch (SessionLimitExceededException ex) {
|
||||
// Ignore
|
||||
}
|
||||
if (this.limitExceeded) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Changing close status " + status + " to SESSION_NOT_RELIABLE.");
|
||||
}
|
||||
status = CloseStatus.SESSION_NOT_RELIABLE;
|
||||
}
|
||||
}
|
||||
this.shutdownInProgress = true;
|
||||
super.close(status);
|
||||
}
|
||||
finally {
|
||||
this.closeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user