Closed kevinmeresse closed 7 years ago
Hi, could you show the exception it is throwing? I'm thinking the problem may be in the disconnect method. https://github.com/eoinsha/JavaPhoenixChannels/blob/master/src/main/java/org/phoenixframework/channels/Socket.java#L208
May need to cancel those timers before closing the socket, I think. Might have similar issues in the onClose and onFailure methods as well
I am getting a similar error. Here are the exceptions that I am getting:
01-30 19:43:11.387 25665-26584/com.myapp.android W/Socket: WebSocket connection error
java.net.SocketTimeoutException: timeout
at okio.Okio$3.newTimeoutException(Okio.java:210)
at okio.AsyncTimeout.exit(AsyncTimeout.java:288)
at okio.AsyncTimeout$2.read(AsyncTimeout.java:242)
at okio.RealBufferedSource.request(RealBufferedSource.java:66)
at okio.RealBufferedSource.require(RealBufferedSource.java:59)
at okio.RealBufferedSource.readByte(RealBufferedSource.java:72)
at okhttp3.internal.ws.WebSocketReader.readHeader(WebSocketReader.java:115)
at okhttp3.internal.ws.WebSocketReader.processNextFrame(WebSocketReader.java:104)
at okhttp3.internal.ws.RealWebSocket.readMessage(RealWebSocket.java:97)
at okhttp3.ws.WebSocketCall.createWebSocket(WebSocketCall.java:152)
at okhttp3.ws.WebSocketCall.access$000(WebSocketCall.java:41)
at okhttp3.ws.WebSocketCall$1.onResponse(WebSocketCall.java:97)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:126)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
Caused by: java.net.SocketException: Socket closed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:151)
at java.net.SocketInputStream.read(SocketInputStream.java:120)
at okio.Okio$2.read(Okio.java:138)
at okio.AsyncTimeout$2.read(AsyncTimeout.java:238)
at okio.RealBufferedSource.request(RealBufferedSource.java:66)
at okio.RealBufferedSource.require(RealBufferedSource.java:59)
at okio.RealBufferedSource.readByte(RealBufferedSource.java:72)
at okhttp3.internal.ws.WebSocketReader.readHeader(WebSocketReader.java:115)
at okhttp3.internal.ws.WebSocketReader.processNextFrame(WebSocketReader.java:104)
at okhttp3.internal.ws.RealWebSocket.readMessage(RealWebSocket.java:97)
at okhttp3.ws.WebSocketCall.createWebSocket(WebSocketCall.java:152)
at okhttp3.ws.WebSocketCall.access$000(WebSocketCall.java:41)
at okhttp3.ws.WebSocketCall$1.onResponse(WebSocketCall.java:97)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:126)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
01-30 19:43:11.387 25665-26583/com.myapp.android E/Socket: Failed to send heartbeat
java.net.SocketException: Socket closed
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:120)
at java.net.SocketOutputStream.write(SocketOutputStream.java:157)
at okio.Okio$1.write(Okio.java:78)
at okio.AsyncTimeout$1.write(AsyncTimeout.java:180)
at okio.RealBufferedSink.emit(RealBufferedSink.java:178)
at okhttp3.internal.ws.WebSocketWriter.writeMessageFrameSynchronized(WebSocketWriter.java:211)
at okhttp3.internal.ws.WebSocketWriter.access$600(WebSocketWriter.java:47)
at okhttp3.internal.ws.WebSocketWriter$FrameSink.close(WebSocketWriter.java:271)
at okio.RealBufferedSink.close(RealBufferedSink.java:236)
at okhttp3.internal.ws.RealWebSocket.sendMessage(RealWebSocket.java:131)
at org.phoenixframework.channels.Socket.push(Socket.java:290)
at org.phoenixframework.channels.Socket$2.run(Socket.java:404)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
01-30 19:43:11.388 25665-26584/com.myapp.android E/ChannelOwner$configureConnection: Error on socket: java.net.SocketTimeoutException: timeout
01-30 19:43:11.637 25665-3092/com.myapp.android D/ChannelOwner$configureConnection: You have Joined
01-30 19:43:16.530 25665-26584/com.myapp.android D/ChannelOwner$configureConnection: You have Joined
01-30 19:43:21.429 25665-26584/com.myapp.android D/ChannelOwner$configureConnection: You have Joined
01-30 19:43:21.430 25665-26584/com.myapp.android E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
Process: com.myapp.android, PID: 25665
java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.next(ArrayList.java:831)
at org.phoenixframework.channels.Socket$PhoenixWSListener.onMessage(Socket.java:82)
at okhttp3.internal.ws.RealWebSocket$1.onMessage(RealWebSocket.java:62)
at okhttp3.internal.ws.WebSocketReader.readMessageFrame(WebSocketReader.java:242)
at okhttp3.internal.ws.WebSocketReader.processNextFrame(WebSocketReader.java:108)
at okhttp3.internal.ws.RealWebSocket.readMessage(RealWebSocket.java:97)
at okhttp3.ws.WebSocketCall.createWebSocket(WebSocketCall.java:152)
at okhttp3.ws.WebSocketCall.access$000(WebSocketCall.java:41)
at okhttp3.ws.WebSocketCall$1.onResponse(WebSocketCall.java:97)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:126)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
Is there any update on #40 getting merged to fix this?
For some reason, sometimes it is still trying to send a heartbeat while the socket is already closed, and it crashes. I guess it would be ok to catch the exception in this context, just so the app doesn't crash. Let me know what you think...