IlyaSkriblovsky / txredisapi

non-blocking redis client for python twisted
Apache License 2.0
235 stars 91 forks source link

ConnectionLost during authentication causes txredisapi to stop retrying #126

Open k2nsloos opened 6 years ago

k2nsloos commented 6 years ago

Hi all, today I noticed that my application using txredisapi suddenly stopped.

The log showed:

[BaseRedisProtocol (TLSMemoryBIOProtocol),client] <twisted.internet.tcp.Connector instance at 0x7f15fcda1440> will retry in 8 seconds
[BaseRedisProtocol (TLSMemoryBIOProtocol),client] <twisted.internet.tcp.Connector instance at 0x7f15fcd85e60> will retry in 9 seconds
[BaseRedisProtocol (TLSMemoryBIOProtocol),client] <twisted.internet.tcp.Connector instance at 0x7f15fcda16c8> will retry in 9 seconds
[BaseRedisProtocol (TLSMemoryBIOProtocol),client] <twisted.internet.tcp.Connector instance at 0x7f15fcd85f38> will retry in 9 seconds
Stopping factory <redis.txredisapi.RedisFactory instance at 0x7f15fcd85d40>
[-] Discarding dead connection.
message repeated 4 times: [ [-] Discarding dead connection.]

So far so good, but on reconnect I got: Redis error: could not auth: Lost connection

Well thought the redis api ought to reconnect if the proper flag was set... On inspection of the BaseRedisProtocol class I noticed the following

 def connectionMade(self):
        if self.factory.password is not None:
            try:
                response = yield self.auth(self.factory.password)
                if isinstance(response, ResponseError):
                    raise response
            except Exception as e:
                self.factory.continueTrying = False
                self.transport.loseConnection()

                msg = "Redis error: could not auth: %s" % (str(e))
                self.factory.connectionError(msg)
                if self.factory.isLazy:
                    log.msg(msg)
                defer.returnValue(None)

The retries are stopped if an exception is raised during auth...