File handle in SpringBootJoranConfigurator should be closed - #51385
Open
dlwldn30 wants to merge 1623 commits into
Open
File handle in SpringBootJoranConfigurator should be closed#51385dlwldn30 wants to merge 1623 commits into
dlwldn30 wants to merge 1623 commits into
Conversation
See spring-projectsgh-50799 Signed-off-by: Ahmed El amraouiyine <amraouiyine@gmail.com>
* spring-projectsgh-50791-grpc-health-overall: Polish "Honor gRPC overall health setting" Honor gRPC overall health setting Closes spring-projectsgh-50799
See spring-projectsgh-51348 Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
Closes spring-projectsgh-51348 * remove-code-tag: Polish "Remove code tag in property description" Remove code tag in property description
AppendableByteArray.reset() was only called from toByteArray(), so an encode that failed part-way left its partial output in the thread-local cached instance. The next value encoded on that thread was then prefixed with it, which in structured logging corrupted the log event following a failed one. Reset the cached instance when it is handed out instead, so the buffer is clean regardless of how the previous use ended. This also covers the early return in toByteArray() for empty content, which returns without resetting. See spring-projectsgh-51156 Signed-off-by: Sumit Kumar Das <skdas5405@gmail.com>
Closes spring-projectsgh-51156 * fix-51154-appendable-byte-array-reset: Polish "Reset cached AppendableByteArray before it is reused" Reset cached AppendableByteArray before it is reused
See micrometer-metrics/micrometer#2297 Co-authored-by: Stéphane Nicoll <stephane.nicoll@broadcom.com>
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>
dlwldn30
force-pushed
the
close-aot-file-content-stream
branch
from
August 17, 2026 05:04
04e3c5b to
16f5fff
Compare
Member
|
Thanks for this PR. I checked out your branch locally to push a few minor tweaks and help get this over the finish line, but my push was rejected with a 403 error. It looks like the "Allow edits from maintainers" option might be unchecked. You need to enable that. You can find the checkbox on the right-hand sidebar of this PR page, right at the bottom. Let me know once it's checked so I can push those updates. Also, please do not unched it going forward and enable it on the other PR you've submitted. |
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.
What Problem This Solves
SpringBootJoranConfigurator.RequireNewOrMatchingContentFileHandlercomparesthe logging resources it is about to write against what is already there:
InputStream.readAllBytes()is documented as "This method does not close theinput stream", and the stream is never assigned to anything, so nothing can
close it afterwards.
During AOT processing the handler is a
FileSystemGeneratedFiles.FileSystemFileHandler,whose content supplier returns
new FileSystemResource(path), so this is a realfile handle rather than an in-memory resource. The handler is used for both
generated files (
MODEL_RESOURCE_LOCATIONandRESOURCE_LOCATION), andfile.exists()is true whenever more than one application context contributesthe same resource.
FileSystemGeneratedFilesitself already uses try-with-resources when itconsumes an
InputStreamSource, so this is inconsistent with the code on theother side of the same interface.
Evidence
Red — fix reverted, test present:
The failure is on the close assertion only. The
IllegalStateExceptionandnon-empty assertions before it pass, so the handler was invoked and the
comparison ran; only the stream was left open.
Green — same command with the fix applied:
Summary
Read the existing content inside a try-with-resources block.
InputStreamwasalready imported, so the production change is three lines.
The test supplies its own
GeneratedFilesand aFileHandlerwhose contentrecords when its stream is closed, then drives the AOT contribution through
applyTo.Related
Same leak class as prior cleanups, all merged:
JarFile is not closed when finding main class from archiveClose FileOutputStream delegate in InspectingOutputStreamClose URLClassLoader in ArchitectureCheckNo open PR touches
SpringBootJoranConfigurator, no closed PR in the last 200has, and I found no existing issue for this. The only commits to this file are
the Spring Framework 7.0.6 snapshot upgrade, the nullability annotations and
the directory restructure, none of which touched this method.
Test plan
aotContributionClosesExistingFileContentfails without theproduction change
:core:spring-boot:test— 3829 tests, 0 failures, 0 errors, 14 skippedcheckFormatMain,checkFormatTest,checkstyleMain,checkstyleTestContributed on behalf of Goatshave.