From 36fb3b3a40b62db81fc87aa1bfe1f0e39701f807 Mon Sep 17 00:00:00 2001 From: An Tao Date: Tue, 25 May 2021 08:33:53 +0800 Subject: [PATCH] Fix a bug when a network failure occurs on Redis connections. (#868) --- nosql_lib/redis/src/RedisConnection.cc | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/nosql_lib/redis/src/RedisConnection.cc b/nosql_lib/redis/src/RedisConnection.cc index b0eab720..7b6a18cf 100644 --- a/nosql_lib/redis/src/RedisConnection.cc +++ b/nosql_lib/redis/src/RedisConnection.cc @@ -265,20 +265,27 @@ void RedisConnection::sendCommandInLoop( void RedisConnection::handleResult(redisReply *result) { - LOG_TRACE << "redis reply: " << result->type; auto commandCallback = std::move(resultCallbacks_.front()); resultCallbacks_.pop(); auto exceptionCallback = std::move(exceptionCallbacks_.front()); exceptionCallbacks_.pop(); - if (result->type != REDIS_REPLY_ERROR) + if (result && result->type != REDIS_REPLY_ERROR) { commandCallback(RedisResult(result)); } else { - exceptionCallback( - RedisException(RedisErrorCode::kRedisError, - std::string{result->str, result->len})); + if (result) + { + exceptionCallback( + RedisException(RedisErrorCode::kRedisError, + std::string{result->str, result->len})); + } + else + { + exceptionCallback(RedisException(RedisErrorCode::kConnectionBroken, + "Network failure")); + } } if (resultCallbacks_.empty()) {