Skip to content
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

Fix reply timeout #100

Closed
wants to merge 2 commits into from
Closed

Conversation

jappja
Copy link
Contributor

@jappja jappja commented Jan 19, 2016

No description provided.

@IlyaSkriblovsky
Copy link
Owner

Hi! You are right that current timeout handling is broken. It is effectively disabled since we never call setTimeout.

But I think your fix needs a bit more to be ideal:

  • Please add setTimeout(None) to connectionLost. Your test_connection_lost doesn't fails with Reactor was unclean only because you monkey-patch callLater. In real life setTimeout will leak delayed call if it is not cancelled in connectionLost
  • resetTimeout doesn't cancels watchdog timer, it only reschedules it to timeOut seconds from now. So if we issue a command, receive a reply and then connection will be idle for timeOut seconds, watchdog timer will fire and will close the connection. I don't think this is what we want. Timeout should be disabled if we received responses to all commands that we issued. This can be done by adding something like this to the end of replyReceived:
if not self.replyQueue.waiting:
    self.setTimeout(None)
  • calling setTimeout multiple times with same argument is effectively the same than calling resetTimeout: it just calls self.__timeoutCall.reset(period). So, each command we send thru connection will reschedule watchdog timer and if we send commands regularly, timeout will never fire even we are not receiving any replies from Redis.

Actually it seems that TimeoutMixin works well for server protocols when we want to close connection if it is idle for N seconds. But we need different behavior: we need to close connection if we doesn't receive reply within N seconds from sending corresponding request. May be it's better to remove TimeoutMixin and replace it with timeout handling at execute_command?..

Please correct me if I'm wrong

@jappja
Copy link
Contributor Author

jappja commented Jan 20, 2016

Yes you are right, TimeoutMixin is intended for server side protocol handling. And this whole timeout handling is much more complicated than it first looked. I'm afraid I don't have time nor deep enough knowledge of the code (or Twisted itself) at this time to have proper fix for it. I'll close this PR and create an issue instead.

@jappja jappja closed this Jan 20, 2016
@jappja
Copy link
Contributor Author

jappja commented Jan 20, 2016

Created #101

@IlyaSkriblovsky
Copy link
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants