mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-24 04:13:28 +01:00
Merge remote-tracking branch 'tor-github/pr/1354' into maint-0.4.2
This commit is contained in:
commit
5c8ecf364a
5
changes/bug31837
Normal file
5
changes/bug31837
Normal file
@ -0,0 +1,5 @@
|
||||
o Minor bugfixes (testing):
|
||||
- When testing port rebinding, don't busy-wait for tor to log. Instead,
|
||||
actually sleep for a short time before polling again. Also improve the
|
||||
formatting of control commands and log messages.
|
||||
Fixes bug 31837; bugfix on 0.3.5.1-alpha.
|
@ -32,15 +32,17 @@ def wait_for_log(s):
|
||||
cutoff = time.time() + LOG_TIMEOUT
|
||||
while time.time() < cutoff:
|
||||
l = tor_process.stdout.readline()
|
||||
l = l.decode('utf8')
|
||||
l = l.decode('utf8', 'backslashreplace')
|
||||
if s in l:
|
||||
logging.info('Tor logged: "{}"'.format(l.strip()))
|
||||
return
|
||||
logging.info('Tor logged: "{}", waiting for "{}"'.format(l.strip(), s))
|
||||
# readline() returns a blank string when there is no output
|
||||
# avoid busy-waiting
|
||||
if len(s) == 0:
|
||||
if len(l) == 0:
|
||||
logging.debug('Tor has not logged anything, waiting for "{}"'.format(s))
|
||||
time.sleep(LOG_WAIT)
|
||||
else:
|
||||
logging.info('Tor logged: "{}", waiting for "{}"'.format(l.strip(), s))
|
||||
fail('Could not find "{}" in logs after {} seconds'.format(s, LOG_TIMEOUT))
|
||||
|
||||
def pick_random_port():
|
||||
@ -120,18 +122,18 @@ if control_socket.connect_ex(('127.0.0.1', control_port)):
|
||||
tor_process.terminate()
|
||||
fail('Cannot connect to ControlPort')
|
||||
|
||||
control_socket.sendall('AUTHENTICATE \r\n'.encode('utf8'))
|
||||
control_socket.sendall('SETCONF SOCKSPort=0.0.0.0:{}\r\n'.format(socks_port).encode('utf8'))
|
||||
control_socket.sendall('AUTHENTICATE \r\n'.encode('ascii'))
|
||||
control_socket.sendall('SETCONF SOCKSPort=0.0.0.0:{}\r\n'.format(socks_port).encode('ascii'))
|
||||
wait_for_log('Opened Socks listener')
|
||||
|
||||
try_connecting_to_socksport()
|
||||
|
||||
control_socket.sendall('SETCONF SOCKSPort=127.0.0.1:{}\r\n'.format(socks_port).encode('utf8'))
|
||||
control_socket.sendall('SETCONF SOCKSPort=127.0.0.1:{}\r\n'.format(socks_port).encode('ascii'))
|
||||
wait_for_log('Opened Socks listener')
|
||||
|
||||
try_connecting_to_socksport()
|
||||
|
||||
control_socket.sendall('SIGNAL HALT\r\n'.encode('utf8'))
|
||||
control_socket.sendall('SIGNAL HALT\r\n'.encode('ascii'))
|
||||
|
||||
wait_for_log('exiting cleanly')
|
||||
logging.info('OK')
|
||||
|
Loading…
Reference in New Issue
Block a user