Copilot commented on code in PR #3590:
URL: https://github.com/apache/brpc/pull/3590#discussion_r4306534403


##########
src/bthread/key.cpp:
##########
@@ -475,6 +481,9 @@ int bthread_keytable_pool_destroy(bthread_keytable_pool_t* 
pool) {
     pthread_rwlock_wrlock(&pool->rwlock);
     pool->destroyed = 1;
     pool->size = 0;
+    pool->deferred_key = deferred_key;
+    pool->delete_deferred_key = delete_deferred_key;

Review Comment:
   This teardown is now deliberately allowed to run while `active_bthreads` is 
nonzero, but `borrow_keytable()` still reads `pool->list` and 
`pool->free_keytables` outside `pool->rwlock` before taking the lock 
(key.cpp:325-339). Clearing those fields here therefore races with those reads; 
under concurrent startup/shutdown this is a data race even if the later locked 
path observes `destroyed`. Move the pointer checks under the rwlock (or 
otherwise synchronize them) before relying on this refcounted teardown.



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