Sending to WebSocket from multiple threads crashes Jetty. Maybe synchronize?
See original GitHub issueActual behavior (the bug)
When I call .send
on a WsSession
from multiple threads, I receive the following:
java.lang.IllegalStateException: Blocking message pending 10000 for BLOCKING
at org.eclipse.jetty.websocket.common.WebSocketRemoteEndpoint.lockMsg(WebSocketRemoteEndpoint.java:130)
at org.eclipse.jetty.websocket.common.WebSocketRemoteEndpoint.sendString(WebSocketRemoteEndpoint.java:386)
at io.javalin.websocket.WsSession.send(WsSession.kt:24)
at ch.hsr.dsl.dwrtc.websocket.WebSocketHandler.onReceiveMessageFromSignaling(WebsocketHandler.kt:117)
Our code calling this (line 117) (slightly modified): session.send("XYZ")
Expected behavior
WsSession.send()
blocks/is synchronized, and message is sent slightly later without a crash
To Reproduce This is a bit hard… I can come up with a little example if you want, but I don’t have the time now (I’ll be back in a few hours). Just assume that our code is called from multiple threads.
Additional context
Only happens when WsSession.send()
is called from multiple threads.
My solution is to make my code @Synchronized
. I suggest synchronizing WsSession.send
. But, if you want to leave that over to users, that’s fine for me too 😃
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Broadcasting websocket message from other thread in jetty
On the server side, Java application using jetty is waiting for connections. Whenever the user sends a message, it broadcasts it to all...
Read more >Eclipse Jetty: Programming Guide
The client libraries are designed to be non-blocking and offer both synchronous and asynchronous APIs and come with many configuration options.
Read more >WebSockets Crash Course - Handshake, Use-cases, Pros ...
WebSockets technology is a bidirectional, full-duplex protocol for ... WebSockets Crash Course - Handshake, Use-cases, Pros & Cons and more.
Read more >Change Log - SymmetricDS - Issue Tracker
0005177: [Bug] File Sync fails to create zip file when modify, followed by delete, followed by create is captured and sent in same...
Read more >26. WebSocket Support
Assuming the handshake succeeds the TCP socket underlying the HTTP upgrade request remains open and both client and server can use it to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks @lroellin. I don’t really mind adding a
@Synchronized
annotation, but I was hoping Jetty would have taken care of this. I added aninput wanted
label, hopefully a Jetty/Java threading pro can chime in.Ok, I tried it using
session.remote.sendString
since it is kind-of fire-and-forget. However, I’m still hitting the error “java.lang.IllegalStateException: Blocking message pending 10000 for BLOCKING”Then I tried
session.remote.sendStringByFuture
but did not check the future. I still sometimes get errors, but I unfortunately dropped the log…I think we can close this issue for now. I’ll see if the Jetty methods help me, and if not I’ll synchronize myself. Could also be that I’m having trouble in my code that is not related to Javalin 😉
Thx for your help!