From 03ad6bc4e197f90efc32fa825de16dcfc1dac906 Mon Sep 17 00:00:00 2001 From: jiumei Date: Wed, 19 Oct 2022 20:18:17 +0800 Subject: [PATCH] fix arena cleared early when parse redis message --- src/brpc/policy/redis_protocol.cpp | 4 +++- src/brpc/redis_command.cpp | 4 ++++ src/brpc/redis_command.h | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/brpc/policy/redis_protocol.cpp b/src/brpc/policy/redis_protocol.cpp index 67e5213307..94524e8b75 100644 --- a/src/brpc/policy/redis_protocol.cpp +++ b/src/brpc/policy/redis_protocol.cpp @@ -190,7 +190,9 @@ ParseResult ParseRedisMessage(butil::IOBuf* source, Socket* socket, wopt.ignore_eovercrowded = true; LOG_IF(WARNING, socket->Write(&sendbuf, &wopt) != 0) << "Fail to send redis reply"; - ctx->arena.clear(); + if(ctx->parser.ParsedArgsSize() == 0) { + ctx->arena.clear(); + } return MakeParseError(err); } else { // NOTE(gejun): PopPipelinedInfo() is actually more contended than what diff --git a/src/brpc/redis_command.cpp b/src/brpc/redis_command.cpp index 2396e457df..82f795051c 100644 --- a/src/brpc/redis_command.cpp +++ b/src/brpc/redis_command.cpp @@ -361,6 +361,10 @@ RedisCommandParser::RedisCommandParser() , _length(0) , _index(0) {} +size_t RedisCommandParser::ParsedArgsSize() { + return _args.size(); +} + ParseError RedisCommandParser::Consume(butil::IOBuf& buf, std::vector* args, butil::Arena* arena) { diff --git a/src/brpc/redis_command.h b/src/brpc/redis_command.h index fc88399570..5ddfb8e99a 100644 --- a/src/brpc/redis_command.h +++ b/src/brpc/redis_command.h @@ -53,6 +53,7 @@ class RedisCommandParser { // in `arena'. ParseError Consume(butil::IOBuf& buf, std::vector* args, butil::Arena* arena); + size_t ParsedArgsSize(); private: // Reset parser to the initial state.