Close the .xsb output when a save is abandoned part-way through - #112
Merged
Conversation
Every saveXxx() in SchemaTypeSystemImpl runs the same sequence: construct an XsbReader, write the component once to fill the string pool, call writeRealHeader() - which opens a Filer output stream - write it again, then writeEnd() to flush and close. Nothing guards the middle. If any write throws, and they all raise SchemaTypeLoaderException on an IO error, writeEnd() is skipped and the .xsb output stream is left open with a partial file behind it. With scomp writing one file per global type, a failure part-way through a large schema leaks a descriptor for each of them. Add XsbReader.closeOutputQuietly(), which releases a stream a completed writeEnd() has already cleared, and call it from a finally in all eight save methods. Closing quietly keeps the original failure from being masked. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.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.
Every
saveXxx()inSchemaTypeSystemImpl(saveIndex,savePointerFile,saveGlobalElement,saveGlobalAttribute,saveModelGroup,saveAttributeGroup,saveIdentityConstraint,saveType) runs the same sequence:Nothing guards the middle. Every write helper raises
SchemaTypeLoaderExceptionon anIOException, so a failing write skipswriteEnd()and leaves the.xsboutput stream open over a partial file. scomp writes one file per global type, so a failure part-way through a large schema leaks a descriptor for each one already opened.Adds
XsbReader.closeOutputQuietly()— a no-op oncewriteEnd()has cleared_output— and calls it from afinallyin all eight save methods. Closing quietly rather than callingwriteEnd()keeps the original failure from being masked by a secondSchemaTypeLoaderException.Added
XsbSaveStreamTest, which serves aFileroutput stream that opens and then fails every write, and asserts the stream is closed. It fails on trunk and passes with this change.compile.scomp.checkin.CompilationTestsstill passes.🤖 Generated with Claude Code