wwbmmm commented on code in PR #3631:
URL: https://github.com/apache/brpc/pull/3631#discussion_r4370438276


##########
src/brpc/socket.cpp:
##########
@@ -2427,17 +2427,20 @@ void Socket::DebugSocket(std::ostream& os, SocketId id) 
{
         os << idsizes[i];
     }
     os << '}';
-    Destroyable* const parsing_context = ptr->parsing_context();
-    Describable* parsing_context_desc = 
dynamic_cast<Describable*>(parsing_context);
-    if (parsing_context_desc) {
-        os << "\nparsing_context=" << butil::class_name_str(*parsing_context) 
<< '{';
-        DescribeOptions opt;
-        opt.verbose = true;
-        IndentingOStream os2(os, 2);
-        parsing_context_desc->Describe(os2, opt);
-        os << '}';
-    } else {
-        os << "\nparsing_context=" << ShowObject(parsing_context);
+    {
+        BAIDU_SCOPED_LOCK(ptr->_parsing_context_mutex);
+        Destroyable* const parsing_context = ptr->parsing_context();
+        Describable* parsing_context_desc = 
dynamic_cast<Describable*>(parsing_context);
+        if (parsing_context_desc) {
+            os << "\nparsing_context=" << 
butil::class_name_str(*parsing_context) << '{';
+            DescribeOptions opt;
+            opt.verbose = true;
+            IndentingOStream os2(os, 2);
+            parsing_context_desc->Describe(os2, opt);
+            os << '}';
+        } else {
+            os << "\nparsing_context=" << ShowObject(parsing_context);
+        }

Review Comment:
   [replied by brpc-oncall robot] The mutex is held only while `/sockets/<id>` 
describes that one socket, so parsing-context transitions of other sockets are 
unaffected. Among the built-in contexts only `H2Context` is `Describable`, and 
its `Describe()` just prints state under its own mutexes. Ref-counting parsing 
contexts would be a much larger change; the mutex declaration documents that 
`Describe()` runs under the lock and must not reset the socket's parsing 
context.



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