How to handle tomcat.websocket.ReadBufferOverflowException with Spring websocket?

Viewed 119

I have a websocket connection to cryptowat.ch websocket which emits crypto currency prices.

...
@Autowired
WebSocketClient client;

var session = client.doHandshake(myWebSocketHandler, myWebSocketHttpHeaders, URI.create(myUrl)).get();
session.send(... //send a subscription message
...

Then I'm starting to receive a lot of binary messages and after 1 sec. the execption is thrown:

org.apache.tomcat.websocket.ReadBufferOverflowException: null
    at org.apache.tomcat.websocket.AsyncChannelWrapperSecure$ReadTask.run(AsyncChannelWrapperSecure.java:312) ~[tomcat-embed-websocket-9.0.43.jar:9.0.43]
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) ~[na:na]
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630) ~[na:na]
    at java.base/java.lang.Thread.run(Thread.java:832) ~[na:na]

How to fix it?
When I use javascript to connect to the websocket then everything is alright:

var conn = new WebSocket(myUrl);

conn.on('message', function (msg) {
...
}

If I limit the subscription query to receive less crypto quotes then it works fine.
I guess the buffer faster receives the data then consumes so even if the limit was huge the exception would happened too.

0 Answers
Related