Repository navigation
aws_s3: close the object scanner when reading an object fails - #4914
Open
a-palamarchuk wants to merge 1 commit into
Open
a-palamarchuk wants to merge 1 commit into
a-palamarchuk wants to merge 1 commit into
Conversation
When the scanner returned an error other than io.EOF, ReadBatch cleared a.object and returned without closing the scanner, and with a.object cleared Close couldn't reach it either. Every object that failed mid-read leaked its scanner and the S3 GetObject response body behind it. Close the scanner on every read error, keeping the original error as the result. Scanners report the failure to the source before returning it, so closing afterwards only releases resources and doesn't acknowledge the object as processed. Fixes redpanda-data#2617 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
josephwoodward
approved these changes
Oct 6, 2026
This branch has not been deployed
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.
Fixes #2617.
What
When the
aws_s3input's scanner returned an error other thanio.EOFwhilereading an object,
ReadBatchcleareda.objectand returned without closing thescanner. Because
a.objectwas already cleared,Closecouldn't reach it latereither. The scanner, and the S3
GetObjectresponse body (plus any decompressionreader) it wraps, leaked for every object that failed mid-read, holding a
connection from the HTTP client's pool.
This closes the scanner on every read error, not only at end of object. The close
result goes into its own variable, so a close failure is logged and can't replace
the original read error returned to the caller.
Is it safe to close after an error?
Yes. Closing doesn't turn the failure into a successful acknowledgement of the S3
object, which in SQS mode would delete the notification:
service.AutoAggregateBatchScannerAcks(every built-in Benthosand Connect scanner) acknowledge the source with the read error inside
NextBatch, through a once-only guard. TheirClosethen only releases thereader; the later acknowledgements are no-ops.
codec:readers in Benthos follow the same pattern.decompress,skip_bom,switch) pass the sourceacknowledgement straight to the scanner they wrap.
So the object is still reported as failed exactly as before; the only change is
that its resources are released.
Tests
TestReadBatchClosesScannerOnErrorplants a scanner that fails on read andrecords whether it was closed. It fails on
main(scanner never closed) andpasses with this change, and also checks the original error is still returned.
go test -race -shuffle=on ./internal/impl/aws/s3/...passes.TestIntegrationS3(LocalStack) passes, including the SQS line-reading subtestsfor both the current scanner and the deprecated
codec:path, which exercise thenormal end-of-object close that this change moves.
golangci-lint runandgolangci-lint fmt --diffare clean.