question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sending to WebSocket from multiple threads crashes Jetty. Maybe synchronize?

See original GitHub issue

Actual 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
tipsycommented, Oct 28, 2018

Thanks @lroellin. I don’t really mind adding a @Synchronized annotation, but I was hoping Jetty would have taken care of this. I added an input wanted label, hopefully a Jetty/Java threading pro can chime in.

0reactions
lroellincommented, Nov 15, 2018

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found