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


##########
src/brpc/rdma/rdma_endpoint.cpp:
##########
@@ -633,16 +629,28 @@ ParseResult 
RdmaEndpoint::ExecuteServerHandshake(butil::IOBuf* source, Socket* s
                      << s->description();
         ep->_state.store(FAILED, butil::memory_order_relaxed);
         s->reset_parsing_context(nullptr);
+        rdma_transport->_on_edge_trigger = 
rdma::RdmaEndpoint::OnNewDataFromTcp;
         return MakeParseError(PARSE_ERROR_ABSOLUTELY_WRONG);
     }
 
     LOG_IF(INFO, FLAGS_rdma_trace_verbose)
         << "Server handshake ends (use rdma v" << ep->_handshake_version
         << ") on " << s->description();
     rdma_transport->_rdma_state = RdmaTransport::RDMA_ON;
-    ep->_state.store(ESTABLISHED, butil::memory_order_relaxed);
+    // Clear any residual TCP data so it cannot pollute the RDMA recv
+    // stream. HandleCompletion appends (not overwrites) to _read_buf,
+    // so leftover bytes would become a prefix to RDMA data and break
+    // parsing. This clear is safe because HandleCompletion only writes
+    // _read_buf after seeing ESTABLISHED (acquire), which is stored
+    // below (release) — strictly after this clear.
+    source->clear();
+    ep->_state.store(ESTABLISHED, butil::memory_order_release);
     s->reset_parsing_context(nullptr);
-    return MakeParseError(PARSE_ERROR_TRY_OTHERS);
+    rdma_transport->_on_edge_trigger = rdma::RdmaEndpoint::OnNewDataFromTcp;
+    // Return NOT_ENOUGH_DATA (not TRY_OTHERS) so that OnNewMessages stops
+    // processing _read_buf immediately, before PollCq starts writing RDMA
+    // data into _read_buf.
+    return MakeParseError(PARSE_ERROR_NOT_ENOUGH_DATA);

Review Comment:
   The preferred_index issue is self-correcting: the first PollCq-driven 
ProcessNewMessage tries the handshake parser, gets a magic mismatch → 
TRY_OTHERS, and switches to the correct parser. This is a one-time cost, and 
should be ok



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