Return on redis connection error. (#1030)

This commit is contained in:
NitroMelon 2021-09-25 00:03:23 +08:00 committed by GitHub
parent 56cb305ae3
commit c9f98e1bf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 0 deletions

View File

@ -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;