songgaoye opened a new pull request, #3615:
URL: https://github.com/apache/brpc/pull/3615

   ### What problem does this PR solve?
   
   Issue Number: resolve
   
   Problem Summary:
   
   `ObjectPool` and `ResourcePool` access `_free_chunks` from multiple threads.
   
   `pop_free_chunk()` checked `_free_chunks.empty()` before acquiring
   `_free_chunks_mutex`, while `push_free_chunk()` modifies the same vector 
under
   the mutex. Concurrent reads and writes of `std::vector` metadata are a C++ 
data
   race; vector growth can also invalidate the metadata being read.
   
   ### What is changed and the side effects?
   
   Changed:
   
   - Remove the unlocked `_free_chunks.empty()` fast path in `ObjectPool`.
   - Remove the same unlocked access in `ResourcePool`.
   - Protect every access to `_free_chunks` in `pop_free_chunk()` with
     `_free_chunks_mutex`.
   
   Side effects:
   
   * Performance effects:
   
     `pop_free_chunk()` now acquires the mutex even when no free chunk is
     available. This removes the unsafe empty-cache fast path and ensures 
correct
     synchronization with concurrent returns.
   
   * Breaking backward compatibility:
   
     None.
   
   * * *


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