Skip to content

ConcurrentModificationException when unsubscribe then detach channel presence listener #743

@QuintinWillison

Description

@QuintinWillison

A customer is experiencing a crash with ably-java version 1.2.10, therefore my understanding is that this is pure JVM (i.e. a server type application - I think it's some kind of a bot), not Android. They have described the scenario to us:

When the UserA encounters a new user join to chatroom he was in , it registers the user presence listener.

presenceChannel.presence.subscribe(member -> {

When UserA no longer needs to track the users presence (not a member of any active chat rooms), the listener is removed:

presenceChannel.presence.unsubscribe();
try {
    presenceChannel.detach();
} catch (AblyException e) {
    throw new BotException(e.toString());
}

The error is encountered mostly when a user goes offline....
The following is the exception stack:

2022-01-25T15:37:29,129|INFO|SomeClient|WebSocketConnectReadThread-132|{"l":"DEBUG","msg":"receive presence event, action: leave, data: {\"userId\":\"SomeUserIdValue\",\"status\":\"Online\",\"customStatus\":\"Available From SomeNamedTool\"}","fnc":"SomeClient.registerUserPresence"} 
2022-01-25T15:37:29,131|DEBUG|UserPresenceManager|WebSocketConnectReadThread-132|updateUserPresence: userId=PATESTFICA138, source=MESSAGING, state=OFFLINE 
(ERROR): io.ably.lib.transport.WebSocketTransport: Unexpected exception processing received binary message 

io.ably.lib.types.AblyException: java.util.ConcurrentModificationException 
    at io.ably.lib.types.AblyException.fromThrowable(AblyException.java:54) 
    at io.ably.lib.transport.ConnectionManager.onMessage(ConnectionManager.java:1080) 
    at io.ably.lib.transport.WebSocketTransport$WsClient.onMessage(WebSocketTransport.java:161) 
    at org.java_websocket.client.WebSocketClient.onWebsocketMessage(WebSocketClient.java:505) 
    at org.java_websocket.drafts.Draft_6455.processFrameBinary(Draft_6455.java:835) 
    at org.java_websocket.drafts.Draft_6455.processFrame(Draft_6455.java:794) 
    at org.java_websocket.WebSocketImpl.decodeFrames(WebSocketImpl.java:381) 
    at org.java_websocket.WebSocketImpl.decode(WebSocketImpl.java:218) 
    at org.java_websocket.client.WebSocketClient.run(WebSocketClient.java:425) 
    at java.base/java.lang.Thread.run(Thread.java:829) 

Caused by: java.util.ConcurrentModificationException 
    at java.base/java.util.ArrayList$Itr.checkForComodification(ArrayList.java:1043) 
    at java.base/java.util.ArrayList$Itr.next(ArrayList.java:997) 
    at io.ably.lib.realtime.Presence$Multicaster.onPresenceMessage(Presence.java:359) 
    at io.ably.lib.realtime.Presence.broadcastPresence(Presence.java:345) 
    at io.ably.lib.realtime.Presence.setPresence(Presence.java:334) 
    at io.ably.lib.realtime.ChannelBase.onPresence(ChannelBase.java:769) 
    at io.ably.lib.realtime.ChannelBase.onChannelMessage(ChannelBase.java:1158) 
    at io.ably.lib.realtime.AblyRealtime$InternalChannels.onMessage(AblyRealtime.java:187) 
    at io.ably.lib.transport.ConnectionManager.onChannelMessage(ConnectionManager.java:1090) 
    at io.ably.lib.transport.ConnectionManager.onMessage(ConnectionManager.java:1075) 
    ... 8 more

(some details redacted above)

Hubspot (internal) threads conversing with this customer are here and, then, here.

┆Issue is synchronized with this Jira Bug by Unito

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working. It's clear that this does need to be fixed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions