Skip to content

fix: Close instruction file and reEncryptInstructionFile GetObject Response Streams - #541

Open
akareddy04 wants to merge 1 commit into
mainfrom
aniravk/fix-539-instruction-file-stream-leak
Open

akareddy04 wants to merge 1 commit into
mainfrom
aniravk/fix-539-instruction-file-stream-leak

Conversation

@akareddy04

Copy link
Copy Markdown
Contributor

Issue #, if available: #539

Description of changes:

loadInstructionFileMetadata parsed the instruction file's GetObject response stream but never closed it. As a result, each decrypt that used an instruction file could leak a pooled HTTP connection until the pool was exhausted. This change closes that stream with try-with-resources, including when parsing fails. It also closes the GetObject stream in reEncryptInstructionFile, which only needs the object's metadata.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Check any applicable:

  • Were any files moved? Moving files changes their URL, which breaks all hyperlinks to the files.

Fixes #539.

ContentMetadataDecodingStrategy.loadInstructionFileMetadata parsed the
instruction file GetObject stream with JsonNodeParser and never closed it.
The parser stops at the end of the JSON value without reading to EOF, so
the instruction file client's pooled connection was never released; after
maxConnections decrypting GetObject calls, requests time out waiting for a
connection. The stream is now closed with try-with-resources, including
when parsing fails.

S3EncryptionClient.reEncryptInstructionFile had the same class of leak: it
called getObject only for the response metadata and never closed the
returned stream. It now closes it right away.

Tests:
- ContentMetadataStrategyTest: instruction file stream is closed after a
  successful parse and after a parse failure.
- S3EncryptionClientReEncryptInstructionFileTest#testReEncryptInstructionFileClosesGetObjectStream:
  unit test that the GetObject stream is closed.
- S3EncryptionClientInstructionFileTest#testGetObjectReleasesInstructionFileConnection:
  integration test with a one-connection instruction file client and
  repeated GetObject calls.
@akareddy04
akareddy04 requested a review from a team as a code owner December 5, 2026 00:30

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant