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

Fix NullReferenceExceptions during serialization #1081

Merged
merged 7 commits into from
Dec 10, 2019

Conversation

j82w
Copy link
Contributor

@j82w j82w commented Dec 5, 2019

Pull Request Template

Description

This fixes observed null reference exceptions during serialization which seems to be caused by some race condition with the custom settings. To avoid this a new JsonSerializer is created for each call.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Closing issues

Put closes #1079

@j82w j82w requested a review from kirillg as a code owner December 5, 2019 20:07
@j82w j82w self-assigned this Dec 5, 2019
@kirankumarkolli
Copy link
Member

We found no issue when it was the default serializer so it does not create a new instance for each call to avoid the garbage collection overhead

Is this validated or an assumption?

@j82w
Copy link
Contributor Author

j82w commented Dec 5, 2019

lt serializer so it does not create a new instance for each call to avoid the garbage collection overhead

All the stack traces are from custom converters path, and the default serializer doesn't have any so it shouldn't be an issue. So it's an assumption.

@kirankumarkolli
Copy link
Member

Micro benchmark showed below

Benchmark:
Thread safe is current implementation
InstanceImpl is when serializer is created for each serialization/de-serialization invocation.

Method Mean Error StdDev StdErr Median Min Q1 Q3 Max Op/s Gen 0 Gen 1 Gen 2 Allocated
ThreadSafeImpl 7.096 us 0.0453 us 0.2216 us 0.0136 us 7.084 us 6.638 us 6.934 us 7.222 us 7.856 us 140,933.6 3.1433 - - 12.88 KB
InstnaceImpl 7.434 us 0.0963 us 0.4817 us 0.0289 us 7.300 us 6.761 us 7.102 us 7.565 us 9.171 us 134,518.7 3.2501 - - 13.31 KB

@j82w j82w merged commit 7edb1a4 into master Dec 10, 2019
@j82w j82w deleted the users/jawilley/bug/newtonsoft_v2 branch December 10, 2019 22:28
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.

NullReferenceExceptions during serialization on Reads/Queries under load
2 participants