Skip to content
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

Report: ConcurrentModificationException when use AckWithTimout... #759

Closed
duan-nguyen opened this issue Jan 19, 2024 · 3 comments
Closed
Labels

Comments

@duan-nguyen
Copy link

duan-nguyen commented Jan 19, 2024

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();
}
}

@Harshvardhan5488
Copy link

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)

Harsh5488 added a commit to Harsh5488/socket.io-client-java that referenced this issue Jul 8, 2024
Using ConcurrentLinkedQueue for safety
darrachequesne pushed a commit that referenced this issue Jul 10, 2024
Clearing the buffer upon timeout could lead to:

```
java.util.ConcurrentModificationException
	at java.base/java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:970)
	at java.base/java.util.LinkedList$ListItr.next(LinkedList.java:892)
	at io.socket.client.Socket$6$1.run(Socket.java:232)
	at java.base/java.util.TimerThread.mainLoop(Timer.java:556)
	at java.base/java.util.TimerThread.run(Timer.java:506)
```

Related:

- #710
- #727
- #758
- #759
@darrachequesne
Copy link
Member

This should be fixed by b00ae8e, included in version 2.1.1.

Please reopen if needed.

@seven4pl
Copy link

seven4pl commented Jan 4, 2025

@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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants