Fatal Exception: java.util.ConcurrentModificationException
Closed this issue · 20 comments
I saw a crash lately with the following stack trace. Any idea if this is related to your lib or the way I interact with it? I've been using this one before and nothing like this happened.
Fatal Exception: java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.next(ArrayList.java:860)
at org.phoenixframework.PhxChannel.trigger(PhxChannel.kt:384)
at org.phoenixframework.PhxSocket.triggerChannelError(PhxSocket.kt:381)
at org.phoenixframework.PhxSocket.remove(PhxSocket.kt:354)
at org.phoenixframework.PhxSocket.remove(PhxSocket.kt:437)
at okhttp3.internal.ws.RealWebSocket.failWebSocket(RealWebSocket.java:570)
at okhttp3.internal.ws.RealWebSocket$2.onFailure(RealWebSocket.java:220)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:161)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
@AdamGrzybkowski do you see any pattern in these? Is it during disconnect, are you removing channels manually, is there a network error, how many channels do you have open at once?
I'll try to dig into this, but if you could figure out if its consistently reproducible, then that would obviously be helpful.
@dsrees It happened only once for now. I do open only one channel. Not sure about other things right now.
hey, I'm getting something similar:
Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'void org.phoenixframework.PhxChannel.trigger(org.phoenixframework.PhxMessage)' on a null object reference
at org.phoenixframework.PhxSocket.triggerChannelError(PhxSocket.kt:387)
at org.phoenixframework.PhxSocket.onConnectionError(PhxSocket.kt:354)
at org.phoenixframework.PhxSocket.onFailure(PhxSocket.kt:443)
at okhttp3.internal.ws.RealWebSocket.failWebSocket(RealWebSocket.java:570)
at okhttp3.internal.ws.RealWebSocket$2.onResponse(RealWebSocket.java:215)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:153)
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:762)
I was wondering could it be a race condition with the channel removing itself from the socket and the socket itself getting a connection error?
Again I'm afraid I have no way to reproduce this
@eoinoconnell that's my theory as well. Thanks for your report, I'll try to see if I can get to this soon.
@dsrees Cool sounds great thanks.
In the mean time I wrapped the changes to channels in synchronise blocks, hopefully that will help, I'll report back if that helps the crash rate, most likely next week.
For reference: https://github.com/8bytes/JavaPhoenixClient
Hey, so that didn't resolve the issue for me, which makes sense to be fair as I was only connecting to one Chanel.
I did take another look at my own code and found that my bug was on my end. I was accidentally initialising the socket more than once so it was to do with a race condition with disconnecting the first while it was connecting to a new instance and closing the socket and Chanel .
Sorry for wasting your time, thanks for the library
@eoinoconnell 👍 not a problem! Glad your issue was resolved.
I hit the original issue here as well. I'll try to pay attention and figure out what I was doing at the time. My trace is slightly different.
E/AndroidRuntime: FATAL EXCEPTION: Timer-929 Process: PID: 32105 java.util.ConcurrentModificationException at java.util.ArrayList$Itr.next(ArrayList.java:860) at org.phoenixframework.PhxChannel.trigger(PhxChannel.kt:384) at org.phoenixframework.PhxPush.trigger(PhxPush.kt:191) at org.phoenixframework.PhxPush$startTimeout$$inlined$schedule$1.run(Timer.kt:149) at java.util.TimerThread.mainLoop(Timer.java:562) at java.util.TimerThread.run(Timer.java:512)
I have same issue. When I send message every 100 ms
com.arstats.retranslator E/AndroidRuntime: FATAL EXCEPTION: Timer-5
Process: com.arstats.retranslator, PID: 12147
java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.next(ArrayList.java:860)
at org.phoenixframework.PhxChannel.trigger(PhxChannel.kt:384)
at org.phoenixframework.PhxPush.trigger(PhxPush.kt:191)
at org.phoenixframework.PhxPush$startTimeout$$inlined$schedule$1.run(Timer.kt:149)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
I have this code
private const val SEND_INTERVAL: Long = 100
socket?.let {
val chatroom = it.channel("receiver:general")
chatroom.join()
.receive("ok") {
while (isStart) {
val payload: HashMap<String, Any> = HashMap()
... init payload
chatroom.push("source", payload)
SystemClock.sleep(SEND_INTERVAL)
}
}
.receive("error") { }
}
Ok I reproduced this again. Like @Helmt89 my code is pushing messages very frequently, about 20 times a second.
@dustinconrad @Helmt89 great! good find. I'll see if I can expose the issue as well and get a fix out for it.
Hi guise) Now after your fix, I have problem with heartbeat after 1 minut - error: Transport: Heartbeat timeout. Attempt to re-establish connection
The default heartbeat timeout is 30s. Did you set it to 60s or is it failing after 2 heartbeats?
FYI, this is now available in the 0.1.4
release
Fail after second heardbeat. Now I disable try/catch logic with heardbeat. This decision work ~ 5 minuts, then I have fatal crash with sochet.
Is the same code that you posted above the code that is failing for you? Also are you getting the same Fatal Exception: java.util.ConcurrentModificationException
error?
Yes this is same code
E/BeaconsActivity: Socket Error null
java.net.SocketException: Connection reset
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113)
at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
at okio.Okio$1.write(Okio.java:79)
at okio.AsyncTimeout$1.write(AsyncTimeout.java:180)
at okio.RealBufferedSink.emit(RealBufferedSink.java:186)
at okhttp3.internal.ws.WebSocketWriter.writeMessageFrame(WebSocketWriter.java:212)
at okhttp3.internal.ws.WebSocketWriter$FrameSink.close(WebSocketWriter.java:253)
at okio.RealBufferedSink.close(RealBufferedSink.java:248)
at okhttp3.internal.ws.RealWebSocket.writeOneFrame(RealWebSocket.java:500)
at okhttp3.internal.ws.RealWebSocket$1.run(RealWebSocket.java:159)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:457)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
This is a different exception than the one this issue was opened for.