torproject / stem

Python controller library for Tor
https://stem.torproject.org/
GNU Lesser General Public License v3.0
257 stars 75 forks source link

controller.authenticate() hanging if not inside "with" block #115

Closed JeremyRand closed 2 years ago

JeremyRand commented 2 years ago

I have the following two test programs, which look to me like they should behave the same:

$ cat both.py 
from stem.control import Controller

with Controller.from_port() as controller:

    print("Authenticating...")
    controller.authenticate()

    print("Tor is running version %s" % controller.get_version())
$ cat only-1.8.0.py 
from stem.control import Controller

controller = Controller.from_port()

print("Authenticating...")
controller.authenticate()

print("Tor is running version %s" % controller.get_version())

With Stem 1.8.0, they both work as expected:

$ python3 both.py 
Authenticating...
Tor is running version 0.4.5.11
$ python3 only-1.8.0.py 
Authenticating...
Tor is running version 0.4.5.11

With Stem master branch (commit hash 4ead96c934838827b8339d780127ac78b15bd1ed), one of them works as expected...

$ python3 both.py 
Authenticating...
Tor is running version 0.4.5.11

...but the other one hangs at controller.authenticate() without exiting:

$ python3 only-1.8.0.py 
Authenticating...

It's not clear to me why Stem master causes these two programs to behave differently. I assume it's a Stem bug, since both of these programs seem like they should work, and it's definitely a breaking change from 1.8.0.

Any ideas?

JeremyRand commented 2 years ago

Python 3.9.9 on Fedora ppc64le if it matters.

atagar commented 2 years ago

Hi Jeremy. This is caused by: https://github.com/torproject/stem/issues/77

JeremyRand commented 2 years ago

Ah, that makes sense. Thanks Damian!