Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support IOContext closing in GeneratorBase #1094

Merged
merged 5 commits into from
Aug 31, 2023

Conversation

pjfanning
Copy link
Member

@pjfanning pjfanning commented Aug 31, 2023

JsonGeneratorImpl closes the IOContext now (part of the BufferRecycler changes in v2.16).
Unfortunately, there are generators in other Jackson modules that now need to close the IOContext (eg TomlGenerator). It would be easier if GeneratorBase was changed and then classes like TomlGenerator could be updated to notify GeneratorBase about their IOContext and let GeneratorBase do closing.

ParserBase has the IOContext close in it so it is pretty strange not to support it in GeneratorBase.

wdyt @cowtowncoder @mariofusco ?

@pjfanning pjfanning changed the title support IOContext closing in GeneratorBase [DRAFT] support IOContext closing in GeneratorBase Aug 31, 2023
@pjfanning pjfanning marked this pull request as draft August 31, 2023 09:17
@pjfanning pjfanning changed the title [DRAFT] support IOContext closing in GeneratorBase support IOContext closing in GeneratorBase Aug 31, 2023
@pjfanning pjfanning marked this pull request as ready for review August 31, 2023 10:36
Copy link
Contributor

@mariofusco mariofusco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I fully agree that the IOContext lifecycle should be managed at the highest possible level in the hierarchy of generators. Is there something similar that should be done also for parsers?

@pjfanning
Copy link
Member Author

Good idea. I fully agree that the IOContext lifecycle should be managed at the highest possible level in the hierarchy of generators. Is there something similar that should be done also for parsers?

ParserBase already manages this. There is a ParserMinimalBase and it doesn't. I don't want to overcomplicate this PR but there might be some merit in also changing ParserMinimalBase in another PR.

@cowtowncoder
Copy link
Member

Hmmh. I'll have to think about this. I agree it makes sense overall -- I think 3.0 had already demoted IOContext further down -- but am slightly concerned about backwards-compatibility with non-FasterXML backends (BSON, MsgPack).
Especially the case of defaulting to passing null IOContext.

But I'll think about this: will probably agree this is necessary.

@pjfanning
Copy link
Member Author

pjfanning commented Aug 31, 2023

Hmmh. I'll have to think about this. I agree it makes sense overall -- I think 3.0 had already demoted IOContext further down -- but am slightly concerned about backwards-compatibility with non-FasterXML backends (BSON, MsgPack). Especially the case of defaulting to passing null IOContext.

But I'll think about this: will probably agree this is necessary.

This is why in the main PR I was trying to argue that the IOContext changes were very damaging. We now have to go and fix all non-JSON parser and generator solutions. I had a look at jackson-dataformats-text today and we now have multiple parsers and generators that don't close their IOContexts.

This PR makes it a bit easier to fix this - because many of the generators extend GeneratorBase. We would still need to change the Generator impl to use the new constructors that take the IOContext as a param.

I can't just remove the old constructors for backward compatibility. I hate nulls at least as much as anyone else but there isn't really a good solution to supporting the deprecated constructors.

@pjfanning
Copy link
Member Author

FasterXML/jackson-dataformats-text#427 doesn't rely on this change. That code explicitly closes the IOContext in the generators.

@cowtowncoder
Copy link
Member

cowtowncoder commented Aug 31, 2023

Right. At the same time, we had to add a life-cycle for recycling BufferRecyclers. I guess we still have the possibility of changing things to make parser/generator handle closing... but, since IOContext is deemed the owner of BufferRecyler that probably wouldn't be any cleaner.

So I think we'll go with it: as you point out, with the default recycler pool, closing really isn't necessary.

EDIT: and although 3.0 does have _ioContext in GeneratorBase that all impls share, ParserMinimalBase doesn't have it -- probably should.

@cowtowncoder
Copy link
Member

Ok yeah, let's go with this.

@cowtowncoder cowtowncoder merged commit 8093f43 into FasterXML:2.16 Aug 31, 2023
5 checks passed
@pjfanning pjfanning deleted the generator-close branch August 31, 2023 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants