]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Avoid a race condition in test_rebind.py
authorteor <teor@torproject.org>
Sat, 6 Oct 2018 21:05:04 +0000 (16:05 -0500)
committerNick Mathewson <nickm@torproject.org>
Fri, 2 Nov 2018 17:14:23 +0000 (13:14 -0400)
If tor terminates due to SIGNAL HALT before test_rebind.py calls
tor_process.terminate(), an OSError 3 (no such process) is thrown.

Fixes part of bug 27968 on 0.3.5.1-alpha.

changes/bug27968 [new file with mode: 0644]
src/test/test_rebind.py

diff --git a/changes/bug27968 b/changes/bug27968
new file mode 100644 (file)
index 0000000..78c8eee
--- /dev/null
@@ -0,0 +1,3 @@
+  o Minor bugfixes (testing):
+    - Avoid hangs and race conditions in test_rebind.py.
+      Fixes bug 27968; bugfix on 0.3.5.1-alpha.
index 7ba3a5796d34cc53370150ec4c6062dea8ce98c0..13e4446cec87a213d0920884f064eeb80c66e3e9 100644 (file)
@@ -6,6 +6,7 @@ import socket
 import os
 import time
 import random
+import errno
 
 def try_connecting_to_socksport():
     socks_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@@ -88,6 +89,14 @@ try_connecting_to_socksport()
 
 control_socket.sendall('SIGNAL HALT\r\n'.encode('utf8'))
 
-time.sleep(0.1)
+wait_for_log('exiting cleanly')
 print('OK')
-tor_process.terminate()
+
+try:
+    tor_process.terminate()
+except OSError as e:
+    if e.errno == errno.ESRCH: # errno 3: No such process
+        # assume tor has already exited due to SIGNAL HALT
+        print("Tor has already exited")
+    else:
+        raise