Skip to content

Commit 09ab218

Browse files
committed
chore: improve logs around the parser error (#5144)
I saw `redis_parser.cc:292] Failed to parse len 69*` logs but it's hard to say whether it's a bug in dragonfly or something else. This pr adds more logs around this case and increases the error level for this message. Signed-off-by: Roman Gershman <roman@dragonflydb.io>
1 parent b3ac766 commit 09ab218

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/facade/redis_parser.cc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,13 @@ auto RedisParser::Parse(Buffer str, uint32_t* consumed, RespExpr::Vec* res) -> R
9292
}
9393

9494
if (resultc.first == INPUT_PENDING) {
95-
DCHECK(str.empty());
95+
if (!str.empty()) {
96+
LOG(DFATAL) << "Did not consume all input: "
97+
<< absl::CHexEscape({reinterpret_cast<const char*>(str.data()), str.size()})
98+
<< ", state: " << int(state_) << " smallbuf: "
99+
<< absl::CHexEscape(
100+
{reinterpret_cast<const char*>(small_buf_.data()), small_len_});
101+
}
96102
StashState(res);
97103
}
98104
return resultc.first;
@@ -281,15 +287,17 @@ auto RedisParser::ParseLen(Buffer str, int64_t* res) -> ResultConsumed {
281287
return {BAD_ARRAYLEN, consumed};
282288
}
283289

284-
// Skip the first character and 2 last ones (\r\n).
290+
// Skip 2 last characters (\r\n).
285291
string_view len_token{s, size_t(pos - 1 - s)};
286292
bool success = absl::SimpleAtoi(len_token, res);
287293

288294
if (success && *res >= -1) {
289295
return ResultConsumed{OK, consumed};
290296
}
291297

292-
LOG(WARNING) << "Failed to parse len " << len_token;
298+
LOG(ERROR) << "Failed to parse len " << absl::CHexEscape(len_token) << " "
299+
<< absl::CHexEscape(string_view{reinterpret_cast<const char*>(str.data()), str.size()})
300+
<< " " << consumed << " " << int(s == small_buf_.data());
293301
return ResultConsumed{BAD_ARRAYLEN, consumed};
294302
}
295303

0 commit comments

Comments
 (0)