Skip to content

Fix ConcurrentModificationException in NioClient.processReadyKeys()#1

Merged
bhaveshthakker merged 2 commits intomasterfrom
test/concurrent-mod-exception
Jun 13, 2025
Merged

Fix ConcurrentModificationException in NioClient.processReadyKeys()#1
bhaveshthakker merged 2 commits intomasterfrom
test/concurrent-mod-exception

Conversation

@bhaveshthakker
Copy link
Copy Markdown
Owner

Problem

Under high concurrency, NioClient.processReadyKeys() could throw a ConcurrentModificationException when iterating over selector.selectedKeys(). This happens if another thread registers a new channel with the selector while the iteration is in progress.

Solution

  • The method now copies selector.selectedKeys() to a new ArrayList before iterating.
  • This prevents concurrent modification during iteration, as recommended by Java NIO best practices.
  • The approach is safe, efficient, and matches the behavior of other high-performance NIO frameworks.

Test Coverage

Impact

  • Prevents application crashes and instability under high load.
  • No change in normal behavior; all ready keys are still processed as expected.

Closes: #

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant