File handle in SpringBootJoranConfigurator should be closed - #51398
Open
dlwldn30 wants to merge 1 commit into
Open
File handle in SpringBootJoranConfigurator should be closed#51398dlwldn30 wants to merge 1 commit into
dlwldn30 wants to merge 1 commit into
Conversation
RequireNewOrMatchingContentFileHandler reads the already generated file through content.getInputStream().readAllBytes(). InputStream.readAllBytes does not close the stream, and the stream is never assigned, so it cannot be closed at all. During AOT processing the content is a FileSystemResource, so each comparison leaks a file handle. FileSystemGeneratedFiles already uses try-with-resources when it consumes an InputStreamSource. Read the existing content inside a try-with-resources block. See spring-projectsgh-51385 Signed-off-by: dlwldn30 <dlwldn30@naver.com>
Author
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.
Sorry for the unrequested rebase on #51385 — you had said you had the branch
locally and I should have left it alone.
Re-submitted from a user-account fork, so "Allow edits from maintainers" applies
here and the tweaks you had locally should push cleanly this time. The change
itself is identical, but the commit is the
4.0.xrebase (915e4775) ratherthan the
mainone you have locally (16f5fffd), since you had retargeted thebase.
SpringBootJoranConfigurator.RequireNewOrMatchingContentFileHandlercompares theresource it is about to write against what is already on disk:
InputStream.readAllBytes()does not close the stream, and the stream is neverassigned to anything, so nothing can close it afterwards. During AOT processing
the handler is a
FileSystemGeneratedFiles.FileSystemFileHandlerwhose contentsupplier returns a
FileSystemResource, so this is a real file handle. It isreached whenever more than one application context contributes the same
resource.
FileSystemGeneratedFilesalready uses try-with-resources on theother side of the same interface.
The fix reads the existing content inside a try-with-resources block, three
lines. The test supplies its own
GeneratedFilesand aFileHandlerwhosecontent records when its stream is closed, then drives the AOT contribution
through
applyTo.Verified on
4.0.x:aotContributionClosesExistingFileContentfails without theproduction change and passes with it,
:core:spring-boot:test3767 tests with0 failures and 14 skipped, and
checkFormatMain,checkFormatTest,checkstyleMainandcheckstyleTestpass.Contributed on behalf of Goatshave.