lh2debug commented on code in PR #3140:
URL: https://github.com/apache/brpc/pull/3140#discussion_r2522288599
##########
src/brpc/controller.cpp:
##########
@@ -1714,4 +1727,31 @@ void Controller::DoPrintLogPrefix(std::ostream& os)
const {
}
}
+
+#if BRPC_SPAN_ENABLE_SHARED_PTR_API
+ControllerPrivateAccessor& ControllerPrivateAccessor::set_span(
+ std::shared_ptr<Span> span) {
+ _cntl->_span = span;
+ return *this;
+}
+#else
+ControllerPrivateAccessor& ControllerPrivateAccessor::set_span(Span* span) {
+ if (span) {
+ _cntl->_span = span->shared_from_this();
+ } else {
+ _cntl->_span.reset();
+ }
+ return *this;
+}
+#endif
+
+SpanPtr ControllerPrivateAccessor::span() const {
+ std::shared_ptr<Span> span_internal = _cntl->_span.lock();
+#if BRPC_SPAN_ENABLE_SHARED_PTR_API
+ return span_internal;
+#else
+ return span_internal.get();
Review Comment:
If the server span waits for the child span to complete before returning (as
is the case in most business scenarios), returning a raw pointer won't cause
any problems.
For example, in a Raft scenario, if the server span returns before the
second follower completes (causing the second follower's client span to be
destroyed), the second follower's RPC callback will retrieve the destroyed
dangling pointer through `ControllerPrivateAccessor::span`.
--
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]