Commit 315215dc authored by juga  's avatar juga
Browse files

fix: !minor. Catch SocketClosed when stopping

When SocketClosed is raised and the scanner is stopping, catch the
exception.
In #28869 similar exceptions were catched, but this was forgotten.

Bugfix v0.6.0.
parent ca72016c
......@@ -240,6 +240,9 @@ def measure_relay(args, conf, destinations, cb, rl, relay):
log.debug('Measuring %s %s', relay.nickname, relay.fingerprint)
s = requests_utils.make_session(
cb.controller, conf.getfloat('general', 'http_timeout'))
# Probably because the scanner is stopping.
if s is None:
return None
# Pick a destionation
dest = destinations.next()
# If there is no any destination at this point, it can not continue.
......@@ -401,13 +404,17 @@ def result_putter_error(target):
measurement -- and return that function so it can be used by someone else
'''
def closure(object):
if settings.end_event.is_set():
return
# The only object that can be here if there is not any uncatched
# exception is stem.SocketClosed when stopping sbws
# An exception here means that the worker thread finished.
log.warning(FILLUP_TICKET_MSG)
# To print the traceback that happened in the thread, not here in the
# main process
traceback.print_exception(type(object), object, object.__traceback__)
# To print the traceback that happened in the thread, not here in
# the main process.
log.warning("".join(traceback.format_exception(
type(object), object, object.__traceback__))
)
return closure
......
......@@ -66,7 +66,7 @@ class CircuitBuilder:
circ_id = c.new_circuit(
path, await_build=True, timeout=timeout)
except (InvalidRequest, CircuitExtensionFailed,
ProtocolError, Timeout) as e:
ProtocolError, Timeout, SocketClosed) as e:
return None, str(e)
return circ_id, None
......
......@@ -24,6 +24,9 @@ def make_session(controller, timeout):
"""
s = TimedSession()
socks_info = stem_utils.get_socks_info(controller)
# Probably because scanner is stopping.
if socks_info is None:
return None
s.proxies = {
'http': 'socks5h://{}:{}'.format(*socks_info),
'https': 'socks5h://{}:{}'.format(*socks_info),
......
......@@ -14,6 +14,7 @@ import os
from sbws.globals import fail_hard
from sbws.globals import (TORRC_STARTING_POINT, TORRC_RUNTIME_OPTIONS,
TORRC_OPTIONS_CAN_FAIL)
from sbws import settings
log = logging.getLogger(__name__)
stream_building_lock = RLock()
......@@ -50,6 +51,11 @@ def add_event_listener(controller, func, event):
def remove_event_listener(controller, func):
try:
controller.remove_event_listener(func)
except SocketClosed as e:
if not settings.end_event.is_set():
log.debug(e)
else:
log.exception(e)
except ProtocolError as e:
log.exception("Exception trying to remove event %s", e)
......@@ -245,9 +251,13 @@ def get_socks_info(controller):
try:
socks_ports = controller.get_listeners(Listener.SOCKS)
return socks_ports[0]
except SocketClosed as e:
if not settings.end_event.is_set():
log.debug(e)
# This might need to return the eception if this happen in other cases
# than when stopping the scanner.
except ControllerError as e:
log.exception("Exception trying to get socks info: %e.", e)
exit(1)
log.debug(e)
def only_relays_with_bandwidth(controller, relays, min_bw=None, max_bw=None):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment