chenBright commented on code in PR #3721:
URL: https://github.com/apache/brpc/pull/3721#discussion_r4514421013
##########
src/bvar/collector.cpp:
##########
@@ -408,15 +488,18 @@ void Collector::dump_thread() {
p = saved_next;
}
}
+ DestroySamples(&root);
}
-// Submit a sample for asynchronous dumping. The Collector holds only the
Collected*
-// pointer (e.g., SpanContainer*). Regardless of which branch is taken below,
the
-// sample will eventually be destroyed via either dump_and_destroy() or
destroy(),
-// both of which call 'delete this' to release the container and decrement the
-// reference count of any managed resources (e.g., shared_ptr<Span>).
+// Submit a sample for asynchronous dumping. Shutdown rejects new submissions.
+// A submission already racing shutdown may still enter the leaked reducer
after
+// its final reset; such samples are reclaimed along with the process.
void Collected::submit(int64_t cpuwide_us) {
- Collector* d = butil::get_leaky_singleton<Collector>();
+ Collector* d = GetCollector();
+ if (d == nullptr) {
+ destroy();
+ return;
Review Comment:
This interleaving is possible. `StopCollector()` is an internal process-exit
hook: it joins the workers and prevents further dump callbacks, while sample
cleanup remains best effort. A submission that already passed the stop check
may enter the retained reducer after the final reset and remain allocated until
process termination.
In 8eed801c20cfaf2100e54577d5eedd2fa65b6657, I've clarified this boundary in
the `StopCollector()` and `submit()` documentation. Calls started after
shutdown completes are destroyed inline; overlapping submissions are not
guaranteed to be reclaimed. This preserves the existing TLS-based submission
path while addressing the shutdown use-after-free.
--
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]