Close DFSInputStream on exception in CachableBlockFile.getBCFile#6377
Open
dlmarion wants to merge 3 commits into
Open
Close DFSInputStream on exception in CachableBlockFile.getBCFile#6377dlmarion wants to merge 3 commits into
dlmarion wants to merge 3 commits into
Conversation
A RateLimitedInputStream is created from the supplied InputStream, which in most cases is a DFSInputStream. However, when BCFile.Reader throws an exception the RateLimitedInputStream is not closed leaving the related DFSInputStream open.
Member
|
try-with-resources wont work here since we need to return the stream but what if we used a try-finally block instead? And add a new boolean to track whether the stream was successfully returned or not. Then in the finally block if it was not successfully returned that means we need to close it. That way in all failure cases, even any that we might not expect here, we can properly close the stream and dont need to duplicate the close logic. |
DomGarguilo
reviewed
May 19, 2026
| RateLimitedInputStream fsIn = | ||
| new RateLimitedInputStream((InputStream & Seekable) inputSupplier.get(), readLimiter); | ||
| BCFile.Reader tmpReader = null; | ||
| byte[] serializedMetadata = cachedMetadataSupplier.get(); |
Member
There was a problem hiding this comment.
If cachedMetadataSupplier.get() can throw, that should probably be moved into the try block too. Otherwise this PR LGTM
Contributor
Author
There was a problem hiding this comment.
I captured that line in the try block in dd8515c
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.
A RateLimitedInputStream is created from the supplied InputStream, which in most cases is a DFSInputStream. However, when BCFile.Reader throws an exception the RateLimitedInputStream is not closed leaving the related DFSInputStream open.