From c9f98e1bf3f92d2db127d6c091615e97dfc132ca Mon Sep 17 00:00:00 2001 From: NitroMelon Date: Sat, 25 Sep 2021 00:03:23 +0800 Subject: [PATCH] Return on redis connection error. (#1030) --- nosql_lib/redis/src/RedisConnection.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/nosql_lib/redis/src/RedisConnection.cc b/nosql_lib/redis/src/RedisConnection.cc index 7b6a18cf..47db2863 100644 --- a/nosql_lib/redis/src/RedisConnection.cc +++ b/nosql_lib/redis/src/RedisConnection.cc @@ -38,11 +38,20 @@ void RedisConnection::startConnectionInLoop() if (redisContext_->err) { LOG_ERROR << "Error: " << redisContext_->errstr; + if (disconnectCallback_) { disconnectCallback_(shared_from_this()); } + + // Strange things have happend. In some kinds of connection errors, such + // as setsockopt errors, hiredis already set redisContext_->c.fd to -1, + // but the tcp connection stays in ESTABLISHED status. And there is no + // way for us to obtain the fd of that socket nor close it. This + // probably is a bug of hiredis. + return; } + redisContext_->ev.addWrite = addWrite; redisContext_->ev.delWrite = delWrite; redisContext_->ev.addRead = addRead;