-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
connectTimeout and replyTimeout #105
Conversation
@@ -1771,6 +1797,8 @@ def sscan(self, key, cursor=0, pattern=None, count=None): | |||
else: | |||
RedisProtocol = BaseRedisProtocol | |||
|
|||
RedisProtocol = BaseRedisProtocol |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line was probably written for debugging purposes and left by mistake
Thanks for your contribution! I've added a couple of minor comments to code, but then noticed, that there is more fundamental flaw in this approach to timeouts. Please consider following test case: class TestTimeout(unittest.TestCase):
. . .
@staticmethod
def _delay(time):
d = defer.Deferred()
reactor.callLater(time, d.callback, None)
return d
@defer.inlineCallbacks
def test_delayed_call(self):
factory = protocol.ServerFactory()
factory.buildProtocol = lambda addr: PingMocker(delay=2)
handler = reactor.listenTCP(8000, factory)
c = yield redis.Connection(host="localhost", port=8000, reconnect=False, replyTimeout=3)
try:
yield self._delay(2)
pong = yield c.ping()
self.assertEqual(pong, "PONG")
finally:
yield handler.stopListening()
yield c.disconnect()
class PingMocker(redis.LineReceiver):
def __init__(self, delay=0):
self.delay = delay
self.calls = []
def lineReceived(self, line):
if line == 'PING':
self.calls.append(reactor.callLater(self.delay, self.transport.write, b"+PONG\r\n"))
def connectionLost(self, reason):
for call in self.calls:
if call.active():
call.cancel() I've added a delay to your As I wrote in #100, I'm still thinking that I surely might be wrong, so please feel free to guard your solution! |
… issued, and no responses were pending
Hi. I intended the code to work exactly as the unit-test you wrote. But I'm having second thoughts about what to call this new feature/behaviour. Let me first explain the problem we're trying to solve for ourselves. We're running in two data-centers, and sometimes a TCP connection between them is closed on one end, without the other end noticing. All requests with pending responses on that connection will then happily block indefinitely. (It may be more appropriate to try to solve this at a lower level though.) I understand that a per-execute-command timeout seems more natural, since you'd only want the timeout to be raised no earlier than replyTimeout. My use case, however, would benefit from letting all pending requests know immediately when we've "given up" on the connection, and given them a chance to re-issue the requests on a fresh connection. Perhaps this particular timeout could be called "closeConnectionIfTimebetweenResponsesExceeds", or something a bit shorter. Am I making any sense? |
Calling Yeah, I've got your point about immediately dropping all pending requests when |
I'm gonna continue experimenting on this branch. Feel free to ignore for now. |
Thanks for your efforts, Árni |
replyTimeout and connectTimeout for txredisapi.
The unit-tests are rather awkward right now. Any critique welcome.
The connectTimeout exists because I'd like to test the case where a connectTimeout should trigger before replyTimeout.