Fix IonFactory resource cleanup on failed construction - #791
Open
Dongnyoung wants to merge 4 commits into
Open
Dongnyoung wants to merge 4 commits into
Dongnyoung wants to merge 4 commits into
Conversation
| if (!inputCleanupDelegated) { | ||
| _closeOnFailedConstruction(in, e); | ||
| } | ||
| _releaseContextOnFailedConstruction(ioCtxt, e); |
Member
There was a problem hiding this comment.
Would this not work in finally block?
Contributor
Author
There was a problem hiding this comment.
Good point, thanks! 😊😊
IonFactory resource cleanup on failed construction
Member
|
Good! Just needs release notes. |
Dongnyoung
force-pushed
the
fix-ion-failed-construction-cleanup
branch
from
September 16, 2026 02:49
b6ff33d to
4b89e7b
Compare
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.
As discussed in #780
Fixes
IonFactoryresource cleanup when parser or generator construction fails after openingFile/Pathresources.IonFactoryhandles these paths separately from the base factory implementations, so the failed-construction cleanup in the base factories does not cover these Ion-specific paths.Parser cleanup
There are two failure points that require different cleanup handling:
Failure before an
IonReaderis created, for example during input decoration.InputStreamopened byIonFactoryis still owned by the outerFile/Pathconstruction path.Failure after an
IonReaderis created, while constructing theIonParser.IonReader/parser construction path.IonReaderis closed there, which also closes the factory-created input stream.The initial implementation used a simple
try/catcharound the outerFile/Pathpath and closed the opened stream on any failure. However, this could close the same stream again when the failure occurs after theIonReaderhas already taken ownership and been closed.The implementation therefore tracks whether ownership has been transferred to the downstream parser construction path. The outer failure handler only closes the stream if that transfer has not happened yet.
IOContextinstances created during parser construction are also released on failure so that theirBufferRecyclerleases are returned.Generator cleanup
The
File/Pathgenerator paths have the corresponding cleanup issue: if generator construction fails afterIonFactoryopens the output stream, the factory-created stream and itsIOContextneed to be cleaned up.Changes
IonReaderwhen parser construction fails after it has been created.File/Pathfailure handler after ownership has been transferred.IOContextinstances on failed parser/generator construction.FileandPathparser/generator failure paths.Verification