python-zk / kazoo

Kazoo is a high-level Python library that makes it easier to use Apache Zookeeper.
https://kazoo.readthedocs.io
Apache License 2.0
1.3k stars 387 forks source link

IAsyncResult wait() has a race. #485

Closed jgh-ds closed 7 years ago

jgh-ds commented 7 years ago

The wait() method of the IAsyncResult has a race. If it is called after the asynchronous operation has completed, the Condition wait() will be stuck forever.

The attached bug.py.txt file demonstrates the problem. The key to triggering it is to call time.sleep(1) before calling wait(). bug.py.txt

Basically, the handlers.utils.AsyncResults.wait() method needs to only call the condition.wait() if the result is not ready(). I've attached a git diff output to illustrate the fix.

diff.txt

Thanks,

Jim Hanko