mmustafasenoglu opened a new pull request, #16384:
URL: https://github.com/apache/dubbo/pull/16384

   ## What is the purpose of the change
   
   Fix a race condition in `FastJson2ObjectInput` where concurrent 
deserialization of JSONB bytes containing `$ref` references produces null 
fields.
   
   ## Brief changelog
   
   - Add striped locks (64 stripes) to `FastJson2ObjectInput` keyed by target 
class
   - Wrap `JSONB.parseObject` calls in `synchronized (getStripe(cls))` blocks
   - Add `getStripe(Class<?>)` helper method
   
   ## Related issue
   
   Fixes #16368
   
   ## Detailed explanation
   
   ### Root cause
   
   When multiple objects reference the same shared singleton (e.g., 
`List.of()`), fastjson2 serialization writes `$ref` references instead of 
duplicating the value. During concurrent deserialization:
   
   1. Multiple threads encounter an ObjectReader cache miss for the same type
   2. fastjson2's `ObjectReaderProvider.getObjectReaderInternal` has a 
non-atomic check-then-act: `if (objectReader == null) { 
createObjectReader(...); putIfAbsent(...); }`
   3. Concurrent `createObjectReader` calls produce corrupted ObjectReader 
instances (incomplete FieldReader arrays)
   4. `$ref` resolution via `fieldReader.accept()` fails silently → fields 
remain null
   
   ### Fix
   
   Striped locks keyed by target class serialize `JSONB.parseObject` calls per 
type. Concurrent deserialization of **different** types is unaffected; only 
**same-type** concurrent deserialization is serialized, preventing the 
fastjson2 race condition.
   
   The 64-stripe design provides sufficient concurrency for typical 
applications while bounding memory usage.
   
   ### How to reproduce
   
   See the reproduction test in the issue: 200 threads with CyclicBarrier, 
cache cleared each round, ~1% of tasks produce null fields.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to