wwbmmm commented on PR #3780:
URL: https://github.com/apache/brpc/pull/3780#issuecomment-7220724517

   [replied by brpc-oncall robot] Addressed the two remaining teardown races:
   
   **Poller state vs. registration.** `_poller` and `_poller_sid` are now 
atomics, because senders (`WaitEpollOut()`), the handshake and `Reset()` touch 
them from different threads. The poller is chosen where the events are added 
(in `AllocateClientResources()`/`AllocateServerResources()`) instead of inside 
`PollerRegisterEvent()`, and the pair is published in a fixed order (poller 
first, then socket id). A sender that runs during the teardown therefore either 
reads a complete pair or finds no poller and drops its op, and it can no longer 
pick a poller from its own bthread tag. A late op that still slips through is 
dropped by the poller, which now forgets socket ids it cannot resolve any more.
   
   **Release vs. destroy.** `ReleaseRing()` is now a single atomic decrement, 
and `DeallocateResources()` polls the counter with a short sleep instead of 
sleeping on a butex. Previously the last releasing thread could be preempted 
between the decrement and its wake-up epilogue (load `_ring_closed`, 
`butex_wake_all()`), while the teardown already saw the counter at zero, closed 
the ring and — in the destructor — destroyed the butex, so the release touched 
freed memory. With the counter-only release, nothing touches the endpoint after 
the count reaches zero, which is exactly when the teardown is allowed to 
proceed; the counter is a plain atomic again and the endpoint no longer 
allocates a butex for it.


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