merlimat opened a new pull request #10142:
URL: https://github.com/apache/pulsar/pull/10142


   ### Motivation
   
   There is a race condition between the `reserveMemory()` and the mutex 
condition notification done when the other thread releases the memory. 
   
   The problem is that we're doing `tryReserveMemory()` in a loop but without 
holding the mutex. It can happen that we `tryReserveMemory()` return false 
(memory is full) and before we acquire the mutex and start waiting on the 
condition, the other thread had already released the memory and tried to 
notify. 
   
   ### Modification
   
   We need to do the `tryReserveMemory()` while holding the mutex, so that we 
don't have this condition. It is fine to do it without mutex the first time, so 
that we can avoid the mutex contention in the normal case, as long as we fall 
back to the mutex and check again.


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