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


   When looking more at the possible race condition, the previous explained 
scenario seems to be possible with a slight variation to it. 
   
   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 2 times in different 
ways and both invalidation call paths call `release()` for the entry** 
    - the EntryImpl instance gets returned to the Recycler object pool, and 
another thread picks it up for usage while it's used in another thread. 
   
   It might sound like a very unlikely situation, but it seems that the problem 
of this issue is also very rare. With enough operations, a very unlikely call 
path will eventually get executed.
   
   I was looking for different ways how entries could get invalidated and 
whether there are locks in place to ensure that an entry doesn't simulaneously 
get invalidated twice. There isn't a solution for this. I believe that the fix 
would be to ensure that an entry cannot be invalidated twice. The method for 
invalidation should be different than calling `release` so that it's possible 
to track when the entry is invalidated. I'll work on a PR with a proposal to 
have a simple fix for the problem this way. The changes will be fairly simple.


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