Skip to content

ConcurrentModificationException when looping connections #921

Closed

Description

@hovis

Describe the bug
ConcurrentModificationException when looping connections returned by getConnections() and a connection is created/removed elsewhere at the same time.

java.util.ConcurrentModificationException
	at java.util.HashMap$HashIterator.nextEntry(HashMap.java:810)
	at java.util.HashMap$KeyIterator.next(HashMap.java:845)
	at java.util.AbstractCollection.toArray(AbstractCollection.java:141)
	at java.util.ArrayList.<init>(ArrayList.java:151)
	at org.java_websocket.server.WebSocketServer.getConnections(WebSocketServer.java:289)
        ...

To Reproduce
Steps to reproduce the behavior:

  1. . Create a thread that requests connections via getConnections() and iterates over the connections (say gathering stats). Run all of that in a loop.
  2. .. Whilst that thread is running connect and disconnect from the WebSocket server using a WebSocket client.
  3. ... Should see an intermittent race condition leading to a ConcurrentModificationException

Expected behavior
No ConcurrentModificationException

Environment(please complete the following information):

  • Version used: 1.3.9 & 1.4.0
  • Java version: 1.8
  • Operating System and version: MacOS / Linux
  • Endpoint Name and version: Chrome/Safari/Firefox

Activity

  1. marci4 commented on Aug 12, 2019

    @marci4
    Collaborator

    Fixed with #922

  2. added this to the Release 1.4.1 milestone on Aug 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions