Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

limitExceeded is never reset in ConcurrentWebSocketSessionDecorator [SPR-17140] #21677

Closed
spring-projects-issues opened this issue Aug 7, 2018 · 6 comments
Assignees
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Aug 7, 2018

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:

  • #20638 Prevent WebSocket buffer overflow through application-level flow control

Referenced from: commits 309ffc6

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Aug 7, 2018

Rossen Stoyanchev commented

ConcurrentWebSocketSessionDecorator puts an upper limit on the send time and the send buffer size. Once those limits are exceeded, a SessionLimitExceededException is raised and the session is terminated. That's the point of those limits, to set a threshold. So this is by design, it's not a bug.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Aug 7, 2018

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?

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Aug 8, 2018

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?

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Aug 10, 2018

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. 

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Aug 10, 2018

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.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Aug 10, 2018

HenryOrz commented

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.