Copilot commented on code in PR #3480:
URL: https://github.com/apache/brpc/pull/3480#discussion_r3849187931


##########
src/brpc/input_messenger.cpp:
##########
@@ -369,7 +369,19 @@ void InputMessenger::OnNewMessages(Socket* m) {
         if (messenger->ProcessNewMessage(m, nr, read_eof, received_us,
                                          base_realtime, last_msg) < 0) {
             return;
-        } 
+        }
+        // If the transport switched its edge trigger during parsing (e.g.,
+        // RDMA handshake completed and edge trigger changed to
+        // OnNewDataFromTcp), stop reading to avoid racing with the new
+        // edge trigger handler on _read_buf. Drain _nevent so future
+        // epoll events can schedule the new edge trigger handler.
+        if (m->_transport->ShouldStopReading()) {
+            while (m->MoreReadEvents(&progress)) {}
+            if (read_eof) {
+                m->SetEOF();
+            }
+            return;

Review Comment:
   `ShouldStopReading()` is checked only after `ProcessNewMessage()` returns, 
but `ProcessNewMessage()` still reads `m->_read_buf.length()` on the 
`PARSE_ERROR_NOT_ENOUGH_DATA` path (see `InputMessenger::ProcessNewMessage` 
around src/brpc/input_messenger.cpp:214). Once `ExecuteServerHandshake()` 
stores `ESTABLISHED`, `PollCq` may start appending to `_read_buf` concurrently, 
so this remaining `length()` access can still race with RDMA appends and 
corrupt IOBuf state or at least skew stats.
   
   Consider moving the stop-reading decision into `ProcessNewMessage()` 
immediately after `CutInputMessage()` returns (before any further `_read_buf` 
access), or otherwise deferring publishing `ESTABLISHED` until after the 
OnNewMessages thread can no longer touch `_read_buf`.



##########
src/brpc/rdma/rdma_endpoint.cpp:
##########
@@ -1593,12 +1621,19 @@ void RdmaEndpoint::PollCq(Socket* m) {
 
         // Just call PrcessNewMessage once for all of these CQEs.
         // Otherwise it may call too many bthread_flush to affect performance.
-        const int64_t received_us = butil::cpuwide_time_us();
-        const int64_t base_realtime = butil::gettimeofday_us() - received_us;
-        InputMessenger* messenger = static_cast<InputMessenger*>(s->user());
-        if (messenger->ProcessNewMessage(
-                    s.get(), bytes, false, received_us, base_realtime, 
last_msg) < 0) {
-            return;
+        // Only call when bytes > 0: when bytes == 0, HandleCompletion wrote
+        // nothing to _read_buf (e.g., IBV_WC_SEND completions, or IBV_WC_RECV
+        // dropped during handshake). Calling ProcessNewMessage with bytes == 0

Review Comment:
   Typo in the comment: `PrcessNewMessage` should be `ProcessNewMessage`.



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