-
Notifications
You must be signed in to change notification settings - Fork 172
fix added to fix following crash #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Fatal Exception: java.lang.IllegalStateException: closed at okhttp3.internal.ws.RealWebSocket.sendMessage(RealWebSocket.java:107) at io.socket.engineio.client.transports.WebSocket$4.call(WebSocket.java:189) at io.socket.engineio.parser.Parser.encodePacket(Parser.java:63) at io.socket.engineio.parser.Parser.encodePacket(Parser.java:42) at io.socket.engineio.client.transports.WebSocket.write(WebSocket.java:184) at io.socket.engineio.client.Transport$3.run(Transport.java:108) at io.socket.thread.EventThread.exec(EventThread.java:55) at io.socket.engineio.client.Transport.send(Transport.java:103) at io.socket.engineio.client.Socket.flush(Socket.java:615) at io.socket.engineio.client.Socket.onDrain(Socket.java:606) at io.socket.engineio.client.Socket.access$1100(Socket.java:31) at io.socket.engineio.client.Socket$6.call(Socket.java:308) at io.socket.emitter.Emitter.emit(Emitter.java:117) at io.socket.engineio.client.transports.WebSocket$3$1.run(WebSocket.java:171) at io.socket.thread.EventThread$2.run(EventThread.java:80) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) at java.lang.Thread.run(Thread.java:818)
@@ -190,6 +190,9 @@ public void call(Object packet) { | |||
} else if (packet instanceof byte[]) { | |||
self.ws.sendMessage(RequestBody.create(BINARY, (byte[]) packet)); | |||
} | |||
} catch (IllegalStateException e) { | |||
logger.fine("websocket closed before we could write"); | |||
doClose(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'd not need to call doClose
again, if the socket is already closed ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nkzawa I have now done that! removed that line.
Thanks for your PR! Added a comment. |
Okay. I will remove doClose(). Apart from that what do you think about the Is it an intelligent thing to do? To catch the illegalstateexception? I tested the app locally it wasn't crashing. I have not yet tested this in
|
Because the problem here is that, Okhttp websocket throws this Which is also supported from the fact that, illegalstateexception has been Please let me know your thoughts, so the we can move forward.
|
@nkzawa I have added the possible replication steps in the description of this PR. Could you please check it? |
Could this be a race condition? @eckovation How big are the payloads you send? If they are fairly big or the phone is slow, you might run into said race condition. |
@chendrak Also, if we just catch the illegalstateexception, what are the downsides of it? |
@eckovation I think catching the |
@eckovation awesome job, thank you!! |
@nkzawa can you release a build as well so that we can release it. |
@nkzawa Sorry for constant pinging. Can you release a new version of repository with the above fix? |
@eckovation Released, sorry to be late! |
@nkzawa @chendrak this pull request addresses the following issue
socketio/socket.io-client-java#346
Could you please confirm if this is logical thing to do?
Fatal Exception: java.lang.IllegalStateException: closed
at okhttp3.internal.ws.RealWebSocket.sendMessage(RealWebSocket.java:107)
at io.socket.engineio.client.transports.WebSocket$4.call(WebSocket.java:189)
at io.socket.engineio.parser.Parser.encodePacket(Parser.java:63)
at io.socket.engineio.parser.Parser.encodePacket(Parser.java:42)
at io.socket.engineio.client.transports.WebSocket.write(WebSocket.java:184)
at io.socket.engineio.client.Transport$3.run(Transport.java:108)
at io.socket.thread.EventThread.exec(EventThread.java:55)
at io.socket.engineio.client.Transport.send(Transport.java:103)
at io.socket.engineio.client.Socket.flush(Socket.java:615)
at io.socket.engineio.client.Socket.onDrain(Socket.java:606)
at io.socket.engineio.client.Socket.access$1100(Socket.java:31)
at io.socket.engineio.client.Socket$6.call(Socket.java:308)
at io.socket.emitter.Emitter.emit(Emitter.java:117)
at io.socket.engineio.client.transports.WebSocket$3$1.run(WebSocket.java:171)
at io.socket.thread.EventThread$2.run(EventThread.java:80)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Indirect Replication Steps:
This bug happens a lot in wild. Typical reason is that, the socket is "sometimes" closed, just when the client was about to write something on it.
If you forcefully close the socket (by calling doClose()) just before the execution of this line (https://github.com/socketio/engine.io-client-java/blob/master/src/main/java/io/socket/engineio/client/transports/WebSocket.java#L189) then it will crash giving out IllegalStateException at the very next moment! But if you add this fix, it won't crash at this place.