This is an automated email from the ASF dual-hosted git repository.

wwbmmm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git


The following commit(s) were added to refs/heads/master by this push:
     new 8f7a4027 Fix incorrect seq id setting in thrift message begin (#2984)
8f7a4027 is described below

commit 8f7a402729057ff2c3314f2bf930ca4435befedf
Author: Bright Chen <chenguangmin...@foxmail.com>
AuthorDate: Sat Jun 7 17:27:06 2025 +0800

    Fix incorrect seq id setting in thrift message begin (#2984)
---
 src/brpc/policy/thrift_protocol.cpp | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/src/brpc/policy/thrift_protocol.cpp 
b/src/brpc/policy/thrift_protocol.cpp
index e3f4b2fa..1e25066d 100755
--- a/src/brpc/policy/thrift_protocol.cpp
+++ b/src/brpc/policy/thrift_protocol.cpp
@@ -81,7 +81,7 @@ ReadThriftMessageBegin(butil::IOBuf* body,
     uint32_t version_and_len_buf[2];
     size_t k = body->copy_to(version_and_len_buf, sizeof(version_and_len_buf));
     if (k != sizeof(version_and_len_buf) ) {
-        return butil::Status(-1, "Fail to copy %" PRIu64 " bytes from body",
+        return butil::Status(-1, "Fail to copy %zu bytes from body",
                              sizeof(version_and_len_buf));
     }
     *mtype = (apache::thrift::protocol::TMessageType)
@@ -95,7 +95,7 @@ ReadThriftMessageBegin(butil::IOBuf* body,
     char buf[sizeof(version_and_len_buf) + method_name_length + 4];
     k = body->cutn(buf, sizeof(buf));
     if (k != sizeof(buf)) {
-        return butil::Status(-1, "Fail to cut %" PRIu64 " bytes", sizeof(buf));
+        return butil::Status(-1, "Fail to cut %zu bytes", sizeof(buf));
     }
     method_name->assign(buf + sizeof(version_and_len_buf), method_name_length);
     // suppress strict-aliasing warning
@@ -120,7 +120,7 @@ WriteThriftMessageBegin(char* buf,
     p += 4;
     memcpy(p, method_name.data(), method_name.size());
     p += method_name.size();
-    *p = htonl(seq_id);
+    *(uint32_t*)p = htonl(seq_id);
 }
 
 bool ReadThriftStruct(const butil::IOBuf& body,
@@ -163,6 +163,7 @@ bool ReadThriftStruct(const butil::IOBuf& body,
         }
 
         xfer += iprot.readStructEnd();
+        (void)xfer;
         iprot.getTransport()->readEnd();
     } catch (std::exception& e) {
         LOG(WARNING) << "Catched thrift exception: " << e.what();
@@ -247,7 +248,7 @@ void ThriftClosure::DoRun() {
         span->set_start_send_us(butil::cpuwide_time_us());
     }
     Socket* sock = accessor.get_sending_socket();
-    MethodStatus* method_status = (server->options().thrift_service ? 
+    MethodStatus* method_status = (server->options().thrift_service ?
         server->options().thrift_service->_status : NULL);
     ConcurrencyRemover concurrency_remover(method_status, &_controller, 
_received_us);
     if (!method_status) {
@@ -321,6 +322,7 @@ void ThriftClosure::DoRun() {
         xfer += oprot.writeFieldEnd();
         xfer += oprot.writeFieldStop();
         xfer += oprot.writeStructEnd();
+        (void)xfer;
 
         oprot.writeMessageEnd();
         oprot.getTransport()->writeEnd();
@@ -343,7 +345,7 @@ void ThriftClosure::DoRun() {
         write_buf.append(buf, sizeof(buf));
         write_buf.append(_response.body.movable());
     }
-    
+
     if (span) {
         span->set_response_size(write_buf.size());
     }
@@ -395,11 +397,9 @@ ParseResult ParseThriftMessage(butil::IOBuf* source,
     return MakeMessage(msg);
 }
 
-inline void ProcessThriftFramedRequestNoExcept(ThriftService* service,
-                                                   Controller* cntl,
-                                                   ThriftFramedMessage* req,
-                                                   ThriftFramedMessage* res,
-                                                   ThriftClosure* done) {
+inline void ProcessThriftFramedRequestNoExcept(ThriftService* service, 
Controller* cntl,
+                                               ThriftFramedMessage* req, 
ThriftFramedMessage* res,
+                                               ThriftClosure* done) {
     // NOTE: done is not actually run before ResumeRunning() is called so that
     // we can still set `cntl' in the catch branch.
     done->SuspendRunning();
@@ -452,7 +452,7 @@ static void EndRunningCallMethodInPool(ThriftService* 
service,
 };
 
 void ProcessThriftRequest(InputMessageBase* msg_base) {
-    const int64_t start_parse_us = butil::cpuwide_time_us();   
+    const int64_t start_parse_us = butil::cpuwide_time_us();
 
     DestroyingPtr<MostCommonMessage> 
msg(static_cast<MostCommonMessage*>(msg_base));
     SocketUniquePtr socket_guard(msg->ReleaseSocket());
@@ -623,7 +623,7 @@ void ProcessThriftResponse(InputMessageBase* msg_base) {
         }
 
         // Read presult
-        
+
         // MUST be ThriftFramedMessage (checked in SerializeThriftRequest)
         ThriftFramedMessage* response = (ThriftFramedMessage*)cntl->response();
         if (response) {
@@ -705,10 +705,11 @@ void SerializeThriftRequest(butil::IOBuf* request_buf, 
Controller* cntl,
 
         // request's write
         xfer += req->raw_instance()->Write(&oprot);
-        
+
         xfer += oprot.writeFieldEnd();
         xfer += oprot.writeFieldStop();
         xfer += oprot.writeStructEnd();
+        (void)xfer;
 
         oprot.writeMessageEnd();
         oprot.getTransport()->writeEnd();


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org
For additional commands, e-mail: dev-h...@brpc.apache.org

Reply via email to