pusher / pusher-websocket-java

Pusher Channels client library for Java targeting general Java and Android
Other
309 stars 143 forks source link

WebsocketNotConnectedException #217

Open Jeff11 opened 5 years ago

Jeff11 commented 5 years ago

With Pusher 2.0.0 SM-G950F, Android 9

Non-fatal Exception: org.java_websocket.exceptions.WebsocketNotConnectedException
  at org.java_websocket.WebSocketImpl.send + 630(WebSocketImpl.java:630)
  at org.java_websocket.WebSocketImpl.send + 607(WebSocketImpl.java:607)
  at org.java_websocket.client.WebSocketClient.send + 344(WebSocketClient.java:344)
  at com.pusher.client.connection.websocket.WebSocketConnection$3.run + 132(WebSocketConnection.java:132)
  at com.pusher.client.util.Factory$1.run + 109(Factory.java:109)
  at java.util.concurrent.ThreadPoolExecutor.runWorker + 1167(ThreadPoolExecutor.java:1167)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run + 641(ThreadPoolExecutor.java:641)
  at java.lang.Thread.run + 764(Thread.java:764)
elverkilde commented 5 years ago

Hi @Jeff11 ,

My best guess is that this happens here: https://github.com/pusher/pusher-websocket-java/blob/master/src/main/java/com/pusher/client/connection/websocket/WebSocketConnection.java#L131-L132

i.e. the connection is dropped, but the internal state here is still CONNECTED. Basically it's a race, and the way the library is currently designed, I don't see how we can prevent that from happening.

My best advice would be to catch that exception, which is would this library should ideally do (i.e. not send the message).