wwbmmm commented on code in PR #3780:
URL: https://github.com/apache/brpc/pull/3780#discussion_r4717612331
##########
src/brpc/ubshm/ub_endpoint.cpp:
##########
@@ -193,15 +193,80 @@ UBShmEndpoint::~UBShmEndpoint() {
}
void UBShmEndpoint::Reset() {
+ // The ring is destroyed by DeallocateResources() or by the poller that
+ // still uses it.
DeallocateResources();
- delete _ub_ring;
- _ub_ring = nullptr;
_poller_sid = INVALID_SOCKET_ID;
+ _poller = nullptr;
_negotiated_data_format = UBR_DATA_FORMAT_NONE;
_state = UNINIT;
}
+// `ring' is not used any more, either because the endpoint never handed it to
+// a poller or because its last user just returned it.
+static void DestroyRing(UBRing* ring) {
+ if (ring == nullptr) {
+ return;
+ }
+ ring->UbrTrxClose();
+ delete ring;
+}
+
+static void* DestroyRingInBthread(void* arg) {
+ DestroyRing(static_cast<UBRing*>(arg));
+ return nullptr;
+}
+
+// Closing the trx may wait for the peer to acknowledge the close, which must
+// not happen in the poller or in a callback of the ring: hand the ring to a
+// bthread instead.
+static void DestroyRingLater(UBRing* ring) {
+ if (ring == nullptr) {
+ return;
+ }
+ bthread_t tid;
+ bthread_attr_t attr = BTHREAD_ATTR_NORMAL;
+ bthread_attr_set_name(&attr, "UBDestroyRing");
+ if (bthread_start_background(&tid, &attr, DestroyRingInBthread, ring) !=
0) {
+ PLOG(WARNING) << "Fail to start bthread to destroy the ring";
+ DestroyRing(ring);
+ }
Review Comment:
[replied by brpc-oncall robot] The helper bthread and its inline fallback
are gone. `DeallocateResources()` now waits for the ring users (poller/senders)
to drop their reference and then closes the ring in the endpoint release path,
which is where the ring was closed before this change; a ring user itself only
drops its reference and never closes the ring.
##########
src/brpc/ubshm/ub_endpoint.cpp:
##########
@@ -193,15 +193,80 @@ UBShmEndpoint::~UBShmEndpoint() {
}
void UBShmEndpoint::Reset() {
+ // The ring is destroyed by DeallocateResources() or by the poller that
+ // still uses it.
DeallocateResources();
- delete _ub_ring;
- _ub_ring = nullptr;
_poller_sid = INVALID_SOCKET_ID;
+ _poller = nullptr;
_negotiated_data_format = UBR_DATA_FORMAT_NONE;
_state = UNINIT;
}
+// `ring' is not used any more, either because the endpoint never handed it to
+// a poller or because its last user just returned it.
+static void DestroyRing(UBRing* ring) {
+ if (ring == nullptr) {
+ return;
+ }
+ ring->UbrTrxClose();
+ delete ring;
+}
+
+static void* DestroyRingInBthread(void* arg) {
+ DestroyRing(static_cast<UBRing*>(arg));
+ return nullptr;
+}
+
+// Closing the trx may wait for the peer to acknowledge the close, which must
+// not happen in the poller or in a callback of the ring: hand the ring to a
+// bthread instead.
+static void DestroyRingLater(UBRing* ring) {
+ if (ring == nullptr) {
+ return;
+ }
+ bthread_t tid;
+ bthread_attr_t attr = BTHREAD_ATTR_NORMAL;
+ bthread_attr_set_name(&attr, "UBDestroyRing");
+ if (bthread_start_background(&tid, &attr, DestroyRingInBthread, ring) !=
0) {
+ PLOG(WARNING) << "Fail to start bthread to destroy the ring";
+ DestroyRing(ring);
+ }
Review Comment:
[replied by brpc-oncall robot] There are no helper bthreads any more: the
ring is closed synchronously inside `DeallocateResources()`, so nothing can
outlive `GlobalRelease()`/`UbrMgrFini()`/`ShmMgrFini()`.
--
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]