镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

fix(batch): make batch failure tracking thread-safe for parallel processing - #2735

Draft
bubanko wants to merge 1 commit into
aws-powertools:mainfrom
bubanko:fix/2712-batch-message-handlers-concurrency-bug
Draft

bubanko wants to merge 1 commit into
aws-powertools:mainfrom
bubanko:fix/2712-batch-message-handlers-concurrency-bug

Conversation

@bubanko

@bubanko bubanko commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Changes

Replicate the thread-safe BatchItemFailure collection implementation from the processBatchInParallel(event, context) method to the overloaded variant that additionally accepting an executor.

Apply this fix to all three BatchMessageHandler implementations.

Using a shared, unsynchronized ArrayList to collect BatchItemFailure instances can lead to lost failure items or cause a worker thread to fail with an ArrayOutOfBoundsException due to concurrent modifications corrupting the list's internals state.

Issue number: #2712


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@bubanko

bubanko commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

I presume duplication is not a blocker for this—the reported code blocks were already duplicates, and resolving this would require a refactor effort which would be too big for a "fix" PR.

@phipag, can we move forward with this or would you like me to try and resolve the duplication?

@phipag

phipag commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

…essing

Replicate the thread-safe `BatchItemFailure` collection implementation from the
`processBatchInParallel(event, context)` method to the overloaded variant that
additionally accepting an executor.

Apply this fix to all three `BatchMessageHandler` implementations.

Using a shared, unsynchronized `ArrayList` to collect `BatchItemFailure`
instances can lead to lost failure items or cause a worker thread to fail with
an `ArrayOutOfBoundsException` due to concurrent modifications corrupting the
list's internals state.

GitHub issue number: aws-powertools#2712
@bubanko
bubanko force-pushed the fix/2712-batch-message-handlers-concurrency-bug branch from 4c2d32a to 1747296 Compare November 2, 2026 10:15
@sonarqubecloud

sonarqubecloud Bot commented Nov 2, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
10.5% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@bubanko

bubanko commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Ah, yes. I don't know why I though the .toList() is a false positive 🤦

As for the unused context parameter—I can remove them, but those methods are untouched by this PR ATM.

This branch has not been deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants