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

Improve Jackson ObjectMapper usage #142

Closed
hzalaz opened this issue Feb 24, 2017 · 18 comments
Closed

Improve Jackson ObjectMapper usage #142

hzalaz opened this issue Feb 24, 2017 · 18 comments
Labels
closed:stale Issue or PR has not seen activity recently enhancement An enhancement or improvement to the SDK that could not be otherwise categorized as a new feature

Comments

@hzalaz
Copy link
Member

hzalaz commented Feb 24, 2017

Ideally we should have a single ObjectMapper per Verifier/Creator instance since they are meant to be shared and there is no need to recreate them per request. However we are creating some additional mappers in some places that can be avoided and the alternatives are:

  1. store in a static var a Mapper (not something I'd like)
  2. make sure we have a single mapper per Verifier/Creator and pass it along to anyone that needs it
  3. same as the previous one but instead of passing the mapper we pass the Reader/Writer

So far the preferred option is #3 but we can start with #2 and then improve later with Writer/Reader

Related to #140

@hzalaz hzalaz added the enhancement An enhancement or improvement to the SDK that could not be otherwise categorized as a new feature label Feb 24, 2017
@cacsar
Copy link

cacsar commented Mar 22, 2017

Not sure if this should be a new enhancement request or not, but the ability to pass in a custom ObjectMapper would be quite useful. It's possible we're just using an old version of Jackson (from Dropwizard), but classes with Optional get rejected because https://github.com/FasterXML/jackson-modules-java8 isn't registered. Whereas if we could inject a custom ObjectMapper we could use the same one we use elsewhere in our code base.

@lbalmaceda
Copy link
Contributor

Hi @cacsar,
Adding a custom ObjectMapper means tying the public API to a specific library and we won't do that. If you have complex classes or just need to get that Optional type, you may parse them manually when #152 get's merged.
Cheers

@cacsar
Copy link

cacsar commented Mar 23, 2017

Ok, in that case I'd recommend registering the Jackson JDK8 module (provided you've dropped Java 7 support in this library) so that Java8 types (like Optional) are supported out of the box.

@thfro
Copy link

thfro commented Oct 18, 2017

How about replacing Jackson with the newly releaed JSON-B 1.0, or its reference implementation respectively? It can be expected that many projects are planning to migrate to JSON-B in the near future, just because there now is a standard API for json binding. And it is tedious to have two binding frameworks in the classpath, only because the JWT library used has a dependency on a proprietary JSON binding solution.

@dmak
Copy link

dmak commented Jan 25, 2018

How about replacing Jackson with the newly releaed JSON-B 1.0

...or wait until Jackson adopts JSON-B, see issue#19.

@skjolber
Copy link
Contributor

So this almost solves itself when #194 is merged? The JWTParser constructor needs a tweak though.

@cbxp
Copy link

cbxp commented Sep 12, 2018

We are experiencing production JVM crashes on Java 10 and 11 inside of Jackson's introspector.
We generate lots of JWT tokens, and generation of each one creates a new ObjectMapper that starts the introspection of Java classes and methods over and over again and eventually crashes the JVM:
https://bugs.openjdk.java.net/browse/JDK-8210044

Maybe it's at least a good idea to tune ObjectMapper parameters and disable some introspection that is not used by JWT generation
https://github.com/FasterXML/jackson-databind/wiki/Mapper-Features

It seems that there are too many features enabled by default.

@skjolber
Copy link
Contributor

See also #255 for reusing the ObjectMapper

@skjolber
Copy link
Contributor

@cbxp @lbalmaceda so basically this would mean that token verification suffers from the same problem?

@angryziber
Copy link

Probably, but we are not running verification at this rate on Java 10 yet :-)

@skjolber
Copy link
Contributor

skjolber commented Sep 12, 2018

Okey (I think perhaps we might be). So this bug, is it just a matter of time before the JVM crashes or does it have to be a frequent operation to fail?

@angryziber
Copy link

That's hard to tell - so far we could reproduce the crash only on production, so testing possibilities are limited. But seems that initializing Jackson only once avoids the problem and makes JWT generation faster. Jackson runs lots of complex code during initialization, so I would turn off any searches that are not needed as well.

@angryziber
Copy link

For some reason, there are quite a lot of JVM crashes reported in Java bug database related to Jackson if you Google for it

@skjolber
Copy link
Contributor

@angryziber @cbxp we raised a ticket and the engineering team was notified, a fix is a few weeks out.

@skjolber
Copy link
Contributor

@lbalmaceda any hope for resolving this in 2018? We're getting more and more JDK 11 applications.

@skjolber
Copy link
Contributor

skjolber commented Feb 1, 2019

#255 has been merged, so that takes care of the JWT validation aspect.

@stale
Copy link

stale bot commented Oct 26, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you have not received a response for our team (apologies for the delay) and this is still a blocker, please reply with additional information or just a ping. Thank you for your contribution! 🙇‍♂️

@stale stale bot added the closed:stale Issue or PR has not seen activity recently label Oct 26, 2019
@stale stale bot closed this as completed Nov 2, 2019
@angelo147
Copy link

Is still any interest about this? I have made an implementation of reusing 2 pools of ObjectMapper instances, one for JWTCreator and one for JWTParser. Seems to work fine for my needs at least.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed:stale Issue or PR has not seen activity recently enhancement An enhancement or improvement to the SDK that could not be otherwise categorized as a new feature
Projects
None yet
Development

No branches or pull requests

9 participants