0

I have a websocket - stomp client application in java. It is working as expected, but when I send a message which is about 16k bytes or greater. It is throwing ConnectionLostException. I checked with a javascript client. In javascript the client sends and receives data in chunks of around 16k bytes and it works fine even if the size increases to 100kbytes. I have checked for size limits in stomp documentation and it is by default ~65kb. What can be the reason for such a scenario because manually chunking the data is a complicated task and will take time. Any advice would be appreciated.

Stack trace is

org.springframework.messaging.simp.stomp.ConnectionLostException: Connection closed
11:48:31.001 [WebSocketClient-AsyncIO-1] ERROR com.demo.webSocket.lib.usage.ExampleClientLib - Connection Closed
    at org.springframework.messaging.simp.stomp.DefaultStompSession.afterConnectionClosed(DefaultStompSession.java:487)
    at org.springframework.web.socket.messaging.WebSocketStompClient$WebSocketTcpConnectionHandlerAdapter.afterConnectionClosed(WebSocketStompClient.java:354)
    at org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter.onClose(StandardWebSocketHandlerAdapter.java:141)
    at org.apache.tomcat.websocket.WsSession.fireEndpointOnClose(WsSession.java:535)
    at org.apache.tomcat.websocket.WsSession.onClose(WsSession.java:513)
    at org.apache.tomcat.websocket.WsFrameBase.processDataControl(WsFrameBase.java:341)
    at org.apache.tomcat.websocket.WsFrameBase.processData(WsFrameBase.java:283)
    at org.apache.tomcat.websocket.WsFrameBase.processInputBuffer(WsFrameBase.java:127)
    at org.apache.tomcat.websocket.WsFrameClient.processSocketRead(WsFrameClient.java:78)
    at org.apache.tomcat.websocket.WsFrameClient.access$300(WsFrameClient.java:31)
    at org.apache.tomcat.websocket.WsFrameClient$WsFrameClientCompletionHandler.completed(WsFrameClient.java:133)
    at org.apache.tomcat.websocket.WsFrameClient$WsFrameClientCompletionHandler.completed(WsFrameClient.java:117)
    at sun.nio.ch.Invoker.invokeUnchecked(Invoker.java:126)
    at sun.nio.ch.Invoker$2.run(Invoker.java:218)
    at sun.nio.ch.AsynchronousChannelGroupImpl$1.run(AsynchronousChannelGroupImpl.java:112)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Aman jangra
  • 248
  • 1
  • 15

1 Answers1

-1

Firstly, can you please provide the stack trace of the ConnectionLostException exception in the client?

Secondly, I think it might be helpful to download the Spring Framework source and link it to the Spring Framework binaries you have so that you can debug and see exactly where and why your code is dying by setting either your IDE to stop on org.springframework.messaging.simp.stomp.ConnectionLostException or put a breakpoint on your StompSession.send() method and step through.

The error could be in Tomcat or in Stomp, it's possible that one or the other can't handle asynchronous or partial messaging.

Also have a look at these other questions as they seem to be related to yours:

Particularly the answer from the first link:

The ... internal spring java websocket stomp client is not capable of partial messaging nor is it configurable with the size of buffer for messages.

Another thing to try might be running this with Glassfish rather than Tomcat.

xtratic
  • 4,136
  • 2
  • 10
  • 28
  • Maximum heap size is 2 gb and initial heap size is 128 mb. When sending via js client, it is by default grouping the data in chunks of 16k bytes while in case of java client, it is sending the data in one shot and if the size increases 16k bytes, connection to web socket server breaks. So I think the problem is in the implementation of stompsession's send method. – Aman jangra Dec 13 '17 at 08:12
  • FYI, I am using org.springframework.messaging.simp.stomp.StompSession for message sending – Aman jangra Dec 13 '17 at 08:21
  • @Amanjangra Could you update your question to include the stack trace of the exception? – xtratic Dec 13 '17 at 14:26
  • added the stack trace, also the send method executes completely without any exception, but the message does not reach the server and in the meantime connectionLostException is encountered. – Aman jangra Dec 14 '17 at 07:43
  • @Amanjangra also updated my answer, I'm hoping one of those resources might help solve this for you. – xtratic Dec 14 '17 at 17:54