lhotari edited a comment on issue #10433:
URL: https://github.com/apache/pulsar/issues/10433#issuecomment-831790136


   UPDATE: The following description of a race condition doesn't seem to be 
possible since a counter in the base class of EntryImpl protects against it. 
([AbstractCASReferenceCounted.release0](https://github.com/apache/pulsar/blob/5e446a67fcacf340d352eeafdce15a78fb971f19/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/util/AbstractCASReferenceCounted.java#L95-L110
   ))
   
   My current assumption of the problem is that a race condition is possible 
when cache invalidation happens with a certain timing. 
   
   The possible race condition:
   
   Code in EntryCacheImpl, asyncReadEntry0 method (code is for branch-2.7):
   
   
https://github.com/apache/pulsar/blob/dcaa1d350fec920ef0ba32b4aeecd2e9604d4824/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/EntryCacheImpl.java#L272-L283
   
   Code for `entries.getRange`, referenced on line 272 in above code snippet:
   
   
https://github.com/apache/pulsar/blob/45ee784f5ef92fc25e970bbf0be34412472173b1/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/util/RangeCache.java#L108-L122
   
   explanation of a possible race condition:
   
   - one thread reads entries from the cache. the entries get marked for use 
with the `value.retain();` call (line 115 in RangeCache).
   - in the meantime, the cache entry gets invalidated and invalidation calls  
`release()` for the entry 
   - the EntryImpl instance gets returned to the Recycler object pool, and 
another thread picks it put for usage. 
   - the thread that read entries from the cache calls `.release()` for the 
instance that is now used by another thread. (line 282 in EntryCacheImpl)
   - since release has been called, it can cause the NPE on 
`managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/EntryImpl.java:
 132: return data.readableBytes();` reported in this issue.
   
   
   
   
   
   
   
   
   


-- 
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.

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


Reply via email to