liumh8 opened a new issue #1155:
URL: https://github.com/apache/incubator-brpc/issues/1155


   **bug描述**
   
一条正常的redis命令调用`brpc::RedisCommandParser::Consume`也可能报错。例如一条命令`"*3\r\n$3\r\nset\r\n$3\r\nkey\r\n$5\r\nvalue\r\n"`解析返回[PARSE_ERROR_ABSOLUTELY_WRONG](https://github.com/apache/incubator-brpc/blob/846f7998799dd3c9103ef743fecc3c75d6dcb7ef/src/brpc/redis_command.cpp#L377)。通过在这行加日志,再次复现时发现这时候的`buf`为`$5\r\nvalue\r\n`,`_parsing_array`
 为`true`,`pfc`却不是`$`。
   
   **可能的原因**
   
`IOBuf`的[fetch1](https://github.com/apache/incubator-brpc/blob/846f7998799dd3c9103ef743fecc3c75d6dcb7ef/src/butil/iobuf.cpp#L1442)函数没有判断当前第一个`BlockRef`的`length`是否为0,如果为0应该要继续读取下一个`BlockRef`。
   
   **具体的例子:**
   ```
   butil::Arena arena;
   std::vector<butil::StringPiece> args;
   brpc::RedisCommandParser parser;
   butil::IOBuf buf;
   buf.append("*3\r\n$3\r\nset\r\n$3\r\nkey\r\n$5\r\nvalue\r\n", 47); // 
buf生成三个BlockRef分别为"*3\r\n$3\r\nset\r\n$3\r\nkey\r\n"、""、"$5\r\nvalue\r\n"
   parser.Consume(buf, &args, &arena); // 返回PARSE_ERROR_ABSOLUTELY_WRONG
   ```
   当`RedisCommandParser 
`解析到`"$5\r\nvalue\r\n"`时,由于第二个`BlockRef`的`length=0`,`IOBuf`的`fetch1`读不到`$`字符,因此返回错误。
   
`length=0`的原因可能是:[iobuf::share_tls_block](https://github.com/apache/incubator-brpc/blob/846f7998799dd3c9103ef743fecc3c75d6dcb7ef/src/butil/iobuf.cpp#L1165)返回了一个[left_space=0](https://github.com/apache/incubator-brpc/blob/846f7998799dd3c9103ef743fecc3c75d6dcb7ef/src/butil/iobuf.cpp#L1169)`的[Block](https://github.com/apache/incubator-brpc/blob/846f7998799dd3c9103ef743fecc3c75d6dcb7ef/src/butil/iobuf.cpp#L369)
   
   
   
   
   
   
   
   


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

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