Skip to content

Commit

Permalink
fix: the bug where iobuf should be enlarged during the replication (#…
Browse files Browse the repository at this point in the history
…1744)

If an empty buffer is passed to the socket Recv function - it returns error 103.
Even if we returned success, this would lead to the endless loop since the parser
requires more data to parse the load.
Fixes #1680

Signed-off-by: Roman Gershman <[email protected]>
  • Loading branch information
romange authored Aug 25, 2023
1 parent f1ac4b0 commit 62a9313
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/server/protocol_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ io::Result<ProtocolClient::ReadRespRes> ProtocolClient::ReadRespReply(base::IoBu
while (!ec) {
uint32_t consumed;
if (buffer->InputLen() == 0 || result == RedisParser::INPUT_PENDING) {
DCHECK_GT(buffer->AppendLen(), 0u);
io::MutableBytes buf = buffer->AppendBuffer();
io::Result<size_t> size_res = sock_->Recv(buf);
if (!size_res) {
Expand Down Expand Up @@ -344,6 +345,11 @@ io::Result<ProtocolClient::ReadRespRes> ProtocolClient::ReadRespReply(base::IoBu
LOG(ERROR) << "Invalid parser status " << result << " for response " << last_resp_;
return nonstd::make_unexpected(std::make_error_code(std::errc::bad_message));
}

// We need to read more data. Check that we have enough space.
if (buffer->AppendLen() < 64u) {
buffer->EnsureCapacity(buffer->Capacity() * 2);
}
}

return nonstd::make_unexpected(ec);
Expand Down

0 comments on commit 62a9313

Please sign in to comment.