Skip to content

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

Merged
phipag merged 1 commit into
aws-powertools:mainfrom
bubanko:fix/2712-batch-message-handlers-concurrency-bug
Nov 4, 2026
Merged

phipag merged 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: Fixes #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

@bubanko
bubanko force-pushed the fix/2712-batch-message-handlers-concurrency-bug branch from 4c2d32a to 1747296 Compare November 2, 2026 10:15
@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.

…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 1747296 to 530ead1 Compare November 3, 2026 08:52
@sonarqubecloud

sonarqubecloud Bot commented Nov 3, 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

@phipag
phipag marked this pull request as ready for review November 4, 2026 10:54
@phipag
phipag requested a review from a team as a code owner November 4, 2026 10:54

@phipag phipag left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @bubanko,

I tested this again locally:

  • Unit tests fail before the code change (not consistently but consistently enough for a regression test)
  • E2E tests pass (I ran this against my AWS account)

This PR is ready to be merged. Thank you for your contribution!

@phipag
phipag merged commit 711d7b0 into aws-powertools:main Nov 4, 2026
11 of 12 checks passed
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.

Bug: BatchMessageHandler implementations can fail or lose failed batch item identifiers when using a custom Executor

2 participants