commit 477c1bcde44e92243bf061f565d9403fa8e31276 Author: Damian Johnson atagar@torproject.org Date: Sun Jun 12 21:41:09 2011 -0700
Shutting down sockets when closed
Each TorCtl instance spawned a socket that would continue to live for the life of the python process. For more information see ticket 2812. --- TorCtl.py | 4 ++++ TorUtil.py | 1 + 2 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/TorCtl.py b/TorCtl.py index b87f5f2..8fac3df 100755 --- a/TorCtl.py +++ b/TorCtl.py @@ -109,6 +109,7 @@ def connect(controlAddr="127.0.0.1", controlPort=9051, passphrase=None): than prompting the user) """
+ conn = None try: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((controlAddr, controlPort)) @@ -132,8 +133,11 @@ def connect(controlAddr="127.0.0.1", controlPort=9051, passphrase=None): print "Connection refused. Is the ControlPort enabled?" else: print "Failed to establish socket: %s" % exc
+ if conn: conn.close() return None except Exception, exc: + if conn: conn.close() + if passphrase and str(exc) == "Unable to authenticate: password incorrect": # provide a warning that the provided password didn't work, then try # again prompting for the user to enter it diff --git a/TorUtil.py b/TorUtil.py index c1bebf9..60d2b2f 100644 --- a/TorUtil.py +++ b/TorUtil.py @@ -230,6 +230,7 @@ class BufSock:
def close(self): self._isDone = True + self._s.shutdown(socket.SHUT_RDWR) self._s.close()
# SocketServer.TCPServer is nuts..
tor-commits@lists.torproject.org