Skip to content

客户端服务端proto不一致的情况下,ParsePbFromIOBuf 会稳定小概率反序列化解析失败 #3207

@W-Xu

Description

@W-Xu

Describe the bug
在客户端的 proto 文件添加新字段之后,服务端未更新的情况下(proto文件见附录),高 qps 的情况下 ParsePbFromIOBuf 会稳定小概率反序列化解析失败。报错路径为:
http_rpc_protocol.cpp文件
if (content_type == HTTP_CONTENT_PROTO) {
if (!ParsePbFromIOBuf(req, req_body)) {
cntl->SetFailed(EREQUEST, "Fail to parse http body as %s",
request_full_name.c_str());
return;
}
……

protocol.cpp文件
bool ParsePbFromIOBuf(google::protobuf::Message* msg, const butil::IOBuf& buf) {
butil::IOBufAsZeroCopyInputStream stream(buf);
return ParsePbFromZeroCopyStreamInlined(msg, &stream);
}

如果把 [IOBufAsZeroCopyInputStream](butil::IOBufAsZeroCopyInputStream stream(buf);) 修改为
std::string flat;
buf.copy_to(&flat);
// 用 ArrayInputStream代替
google::protobuf::io::ArrayInputStream ais(flat.data(), flat.size());
问题就会修复。

1、辛苦确认一下,这个地方是否有问题?或者有更好的使用建议吗?
2、如果有问题,这个地方用的 IOBufAsZeroCopyInputStream 看起来是问题所在,是否有更好修改建议?

附录:
proto文件
message BatchRequest {
string aaa = 1;
repeated int32 bbb = 2;
string ccc = 3;
repeated Request requests = 4;
int32 ddd = 5;
repeated uint64 eee = 6;
int32 fff = 7;

// Optional. name
// 客户端添加这个字段,服务端不添加这个字段有问题
string name = 8;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions