Skip to content

Fix fastjson2 concurrent ref deserialization#16369

Open
goutamadwant wants to merge 1 commit into
apache:3.3from
goutamadwant:fix/dubbo-16368-fastjson2-concurrent-ref
Open

Fix fastjson2 concurrent ref deserialization#16369
goutamadwant wants to merge 1 commit into
apache:3.3from
goutamadwant:fix/dubbo-16368-fastjson2-concurrent-ref

Conversation

@goutamadwant

Copy link
Copy Markdown

What is the purpose of the change?

Fixes #16368.

Fastjson2 JSONB deserialization can lose nested fields when multiple threads deserialize the same $ref-heavy payload for the same target class at the same time. In the failing case, shared lists referenced by multiple child objects can become null after concurrent deserialization.

This change routes both FastJson2ObjectInput#readObject overloads through a shared helper and synchronizes the fastjson2 parse per requested target class. The lock is backed by ClassValue, so it does not retain application classes or classloaders, and unrelated DTO classes can still deserialize concurrently.

The regression test serializes an object graph with shared nested lists, verifies a single read succeeds, then repeatedly deserializes the same payload from 200 threads while clearing fastjson2 reader caches between rounds. Without the fix, the test reports a non-zero count of null nested fields.

Tests:

  • Focused repro: FastJson2SerializationTest#testConcurrentReadObjectWithReferences
  • Targeted slice: FastJson2SerializationTest,TypeMatchTest
  • Surefire result: 807 tests, 0 failures, 0 errors, 0 skipped

Checklist

  • Make sure there is a GitHub_issue field for the change.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test to verify your logic correction.
  • Make sure GitHub actions can pass.

@codecov-commenter

codecov-commenter commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.47%. Comparing base (ed0e11e) to head (f20ccc7).

Files with missing lines Patch % Lines
...mmon/serialize/fastjson2/FastJson2ObjectInput.java 70.00% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##                3.3   #16369      +/-   ##
============================================
- Coverage     60.86%   60.47%   -0.39%     
+ Complexity    11768    10245    -1523     
============================================
  Files          1953     1953              
  Lines         89260    89264       +4     
  Branches      13471    13470       -1     
============================================
- Hits          54329    53986     -343     
- Misses        29350    29646     +296     
- Partials       5581     5632      +51     
Flag Coverage Δ
integration-tests-java21 ?
integration-tests-java8 ?
samples-tests-java21 32.15% <70.00%> (-0.01%) ⬇️
samples-tests-java8 29.72% <0.00%> (-0.11%) ⬇️
unit-tests-java11 59.10% <60.00%> (+<0.01%) ⬆️
unit-tests-java17 ?
unit-tests-java21 58.56% <60.00%> (+<0.01%) ⬆️
unit-tests-java25 58.54% <60.00%> (+<0.01%) ⬆️
unit-tests-java8 59.10% <60.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

[Bug] Concurrent deserialization with $ref references produces null fields in FastJson2Serialization

2 participants