socketio / socket.io-client-java

Full-featured Socket.IO Client Library for Java, which is compatible with Socket.IO v1.0 and later.
https://socketio.github.io/socket.io-client-java/installation.html
Other
5.3k stars 967 forks source link

Report: ConcurrentModificationException when use AckWithTimout... #759

Closed duan-nguyen closed 2 weeks ago

duan-nguyen commented 6 months ago

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:

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 commented 1 month ago

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)

darrachequesne commented 2 weeks ago

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.