GH-11352: Propagate a failing close() when writing files - #11353
Open
dlwldn30 wants to merge 1 commit into
Open
Conversation
Fixes: spring-projects#11352 cleanUpFileState() discarded every IOException, including the one raised by closing the buffered writer or stream. close() is where the buffer is flushed, so a full disk was reported as a successful write and the truncated temporary file was still promoted onto the result file. Let cleanUpFileState() propagate, and call it on the success path where the caller can see the failure. On the failure path the close error is attached as a suppressed exception instead, so the exception already on its way out is not masked. clearState() still runs either way and the APPEND_NO_FLUSH branch is untouched. Signed-off-by: Jiwoo Lee <dlwldn30@naver.com>
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: #11352
cleanUpFileState()discarded everyIOException, including the one raised by closing the buffered writer or stream. All three write paths call it from afinallyblock, andclose()is where the buffer is flushed, so a full disk was reported as a successful write and the truncated temporary file was still renamed onto the result file.cleanUpFileState()now propagates and the callers invoke it on the success path, where a failure reaches the caller. On the failure path it goes throughcleanUpFileStateSuppressing(), which attaches the close error to the exception already on its way out instead of replacing it, the way try-with-resources does.clearState()still runs in both cases and theAPPEND_NO_FLUSHbranch is unchanged. Keeping a singlefinallyand handing it the in-flight exception would work too and would keep the call sites shorter; happy to reshape it that way if you prefer.Verified with
./gradlew --rerun-tasks :spring-integration-file:check: 332 tests, 0 failures, 6 skipped, checkstyle clean on main and test.FileWritingMessageHandleris referenced only from this module, so that is the whole affected surface. Reverting just the production file makes the new test fail and leaves the other 331 passing.Contributed on behalf of Goatshave.