fix(sqs): prevent ConcurrentModificationException on container stop#1632
Open
Baqirrizvidev wants to merge 2 commits into
Open
fix(sqs): prevent ConcurrentModificationException on container stop#1632Baqirrizvidev wants to merge 2 commits into
Baqirrizvidev wants to merge 2 commits into
Conversation
- Replace obsolete .collect(Collectors.toList()) with standard Java 16+ .toList() - Remove unused java.util.stream.Collectors import
When an SQS message listener container is stopped, AbstractPollingMessageSource.stop() iterates over this.pollingFutures to cancel active polls. Each future has a whenComplete callback registered in managePollingFuture that synchronously/concurrently removes itself from the pollingFutures collection. Iterating over the collection while elements are being removed throws a ConcurrentModificationException. This commit prevents the exception by taking a shallow snapshot copy of the pollingFutures collection before iterating and cancelling the futures. Fixes awspring#1594
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When an SQS message listener container is stopped under heavy load,
AbstractPollingMessageSource.stop()iterates overthis.pollingFuturesto cancel active polls. Each future has awhenCompletecallback registered inmanagePollingFuturethat removes itself from thepollingFutureslist.Cancelling the future inside the iteration loop triggers the callback synchronously/concurrently, modifying the list while it is being iterated, which throws a
ConcurrentModificationExceptionand halts proper container shutdown.This commit resolves the issue by taking a snapshot copy (
new ArrayList<>(this.pollingFutures)) of the collection before iterating and cancelling, decoupling iteration from list modifications.Fixes #1594