Server adapters release buffers on error/cancel

Review and update Servlet and Undertow adapters to release any data
buffers they be holding on to at the time of error or cancellation.

Also remove onDiscard hooks from Reactor and Undertow request body.
For Reactor we expect it to be handled. For Undertow there isn't
any Reactor Core upstream for the callback to be useful.

Issue: SPR-17410
This commit is contained in:
Rossen Stoyanchev
2018-10-19 21:45:14 -04:00
parent 149d416e8e
commit 862dd23975
10 changed files with 389 additions and 42 deletions

View File

@@ -260,11 +260,23 @@ public abstract class AbstractListenerWebSocketSession<T> extends AbstractWebSoc
rsReadLogger.trace(getLogPrefix() + "Received " + message);
}
if (!this.pendingMessages.offer(message)) {
discardData();
throw new IllegalStateException(
"Too many messages. Please ensure WebSocketSession.receive() is subscribed to.");
}
onDataAvailable();
}
@Override
protected void discardData() {
while (true) {
WebSocketMessage message = (WebSocketMessage) this.pendingMessages.poll();
if (message == null) {
return;
}
message.release();
}
}
}
@@ -289,6 +301,7 @@ public abstract class AbstractListenerWebSocketSession<T> extends AbstractWebSoc
else if (rsWriteLogger.isTraceEnabled()) {
rsWriteLogger.trace(getLogPrefix() + "Sending " + message);
}
// In case of IOException, onError handling should call discardData(WebSocketMessage)..
return sendMessage(message);
}
@@ -313,6 +326,11 @@ public abstract class AbstractListenerWebSocketSession<T> extends AbstractWebSoc
}
this.isReady = ready;
}
@Override
protected void discardData(WebSocketMessage message) {
message.release();
}
}
}