limitExceeded is never reset in ConcurrentWebSocketSessionDecorator [SPR-17140] #21677
Comments
Rossen Stoyanchev commented
|
HenryOrz commented @Rossen Stoyanchev Thank you! You are right, I have read the comment of the class, It's not a bug, I misunderstand it. But I'm puzzled by this feature, if buffer limit was exceeded, and I have also caught the SessionLimitExceededException, but I still want to send message, how can I restore it? I have tried to new ConcurrentWebSocketSessionDecorator to replace the exceeded one, but there is no public access to get the buffer, which means I lost the message in the buffer of old one. Thanks to @Juergen Hoeller for linking issue #20638, It's reminds me to do some basic check by method getBufferSize(). But if I just check it simply(just like the code below). It may bring some problem like race condition, the code will be complex if I want to make it correct
if((decorator.getBufferSize() + messageSize) < decorator.getBufferSizeLimit()){
decorator.sendMessage();
} Is there any way to send message more gracefully after limits exceeded?
Might we have a method to flush buffer and reset the limitExceed flag when limits exceeded?Just like try {
decorator.sendMessage();
} catch (SessionLimitExceededException e) {
decorator.flushAndReset();
} Or could we remove the limitExceed condition in method tryFlushMessageBuffer() , and reset the limitExceed flag after all the message in buffer was flushed? |
Rossen Stoyanchev commented There are only so many ways to deal with overflow. Currently it simply drops the connection once the limit is reached. We could add an option to enable an alternative overflow strategy such as to drop messages. Is that what you're looking for? |
HenryOrz commented Thank you! That is what I'm looking for! More precisely, I want a strategy to flush buffer when buffer overflow. I have commit a pull request on github. |
Rossen Stoyanchev commented I've implemented this a little differently. Basically it's controlled through an OverflowStrategy enum flag on the constructor and automatically applied when the limit is reached. |
HenryOrz commented Thank you! |
HenryOrz opened SPR-17140 and commented
In a spring-websocket application, Once org.springframework.web.socket.handler.ConcurrentWebSocketSessionDecorator bufferSizeLimit was exceeded, the method sendMessage() does't work anymore.
There is a limitExceeded flag in ConcurrentWebSocketSessionDecorator, when the bufferSizeLimit was exceeded, the flag will set to true, but it's never reset to false. The method tryFlushMessageBuffer() which called by sendMessage() will check the limitExceeded flag, so the sendMessage() does't work after bufferSizeLimit was exceeded
Thanks Artem Bilan for answer my question on stackoverflow
Affects: 4.3.18, 5.0.8
Reference URL: https://stackoverflow.com/questions/51723413/how-to-flush-buffer-when-concurrentwebsocketsessiondecorator-buffersizelimit-exc
Issue Links:
Referenced from: commits 309ffc6
The text was updated successfully, but these errors were encountered: