socket.io-client-java icon indicating copy to clipboard operation
socket.io-client-java copied to clipboard

Report: ConcurrentModificationException when use AckWithTimout...

Open duan-nguyen opened this issue 2 years ago • 1 comments

Describe the bug Report: ConcurrentModificationException when use AckWithTimout... (no issues with regular Ack(), only with AckWithTimout because of concurrent / thread-safe ...)

To Reproduce

Please fill the following code example:

Client

multi-thread...
        socket.emit("echo", null, new AckWithTimeout(3000) {
			@Override
			public void onSuccess(Object... args) {
				log.info(args[0].toString());	
			}
			@Override
			public void onTimeout() {
				log.warn("WARN: timout occured...");
			}
		});

Platform:

  • MacOS or any...

Error java.util.ConcurrentModificationException at java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:966) at java.util.LinkedList$ListItr.next(LinkedList.java:888) at io.socket.client.Socket$6$1.run(Socket.java:232) at java.util.TimerThread.mainLoop(Timer.java:555) at java.util.TimerThread.run(Timer.java:505)

Fix needed Need to rewrite Socket.class to support thread-safe???? while (iterator.hasNext()) { if (iterator.next().id == ackId) { <=== 232 iterator.remove(); } }

duan-nguyen avatar Jan 19 '24 02:01 duan-nguyen

I am Working on an Android Project in Kotlin that uses this library for socket. I am facing the same issue. Is there any fix for it? This crash appears a lot many times on the Prod.

Please provide any fix or update in the library. Thanks

Here is the stack trace: (io.socket.client.Socket$6$1.run (Socket.java:232)) Fatal Exception: java.util.ConcurrentModificationException: at java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:970) at java.util.LinkedList$ListItr.next(LinkedList.java:892) at io.socket.client.Socket$6$1.run(Socket.java:232) at java.util.TimerThread.mainLoop(Timer.java:563) at java.util.TimerThread.run(Timer.java:513)

Harshvardhan5488 avatar Jun 19 '24 09:06 Harshvardhan5488

This should be fixed by https://github.com/socketio/socket.io-client-java/commit/b00ae8eec1ef0aa5094fca7fad918a437603eb12, included in version 2.1.1.

Please reopen if needed.

darrachequesne avatar Jul 11 '24 12:07 darrachequesne

@darrachequesne hi, I have a very similar case with io.socket.client.Socket.clearAcks, when sending about 50 ACK's with timeout: 4 diffrent devices, Android 13 (SDK 33) and Android 14 (SDK 34), newest socket.io-client-java (version 2.1.1)

java.util.ConcurrentModificationException

Exception java.util.ConcurrentModificationException:
  at java.util.HashMap$HashIterator.nextNode (HashMap.java:1603)
  at java.util.HashMap$ValueIterator.next (HashMap.java:1631)
  at io.socket.client.Socket.clearAcks (Socket.java:294)
  at io.socket.client.Socket.onclose (Socket.java:286)
  at io.socket.client.Socket.access$400 (Socket.java:19)
  at io.socket.client.Socket$2$4.call (Socket.java:106)
  at io.socket.emitter.Emitter.emit (Emitter.java:117)
  at io.socket.client.Manager.onclose (Manager.java:472)
  at io.socket.client.Manager.access$1100 (Manager.java:22)
  at io.socket.client.Manager$4.call (Manager.java:349)
  at io.socket.emitter.Emitter.emit (Emitter.java:117)
  at io.socket.engineio.client.Socket.onClose (Socket.java:822)
  at io.socket.engineio.client.Socket.onError (Socket.java:784)
  at io.socket.engineio.client.Socket.access$900 (Socket.java:29)
  at io.socket.engineio.client.Socket$4.call (Socket.java:340)
  at io.socket.emitter.Emitter.emit (Emitter.java:117)
  at io.socket.engineio.client.Transport.onError (Transport.java:66)
  at io.socket.engineio.client.transports.WebSocket.access$400 (WebSocket.java:22)
  at io.socket.engineio.client.transports.WebSocket$1$5.run (WebSocket.java:107)
  at io.socket.thread.EventThread$2.run (EventThread.java:80)
  at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1145)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:644)
  at java.lang.Thread.run (Thread.java:1012)

seven4pl avatar Jan 04 '25 00:01 seven4pl