[tor-commits] [sbws/master] scanner, destination: Log all possible exceptions

juga at torproject.org juga at torproject.org
Thu Feb 28 11:09:52 UTC 2019


commit c4f502c1d05570d6069680b3a91cf9a1709d6e7a
Author: juga0 <juga at riseup.net>
Date:   Wed Feb 27 17:30:59 2019 +0000

    scanner, destination: Log all possible exceptions
    
    that can happen from requests, so that they can later be stored in
    a Result.
---
 sbws/core/scanner.py    | 8 ++------
 sbws/lib/destination.py | 5 +----
 2 files changed, 3 insertions(+), 10 deletions(-)

diff --git a/sbws/core/scanner.py b/sbws/core/scanner.py
index e99b8cd..3fbd378 100644
--- a/sbws/core/scanner.py
+++ b/sbws/core/scanner.py
@@ -84,8 +84,6 @@ def timed_recv_from_server(session, dest, byte_range):
 
     start_time = time.time()
     HTTP_GET_HEADERS['Range'] = byte_range
-    # TODO:
-    # - What other exceptions can this throw?
     # - response.elapsed "measures the time taken between sending the first
     #   byte of the request and finishing parsing the headers.
     #   It is therefore unaffected by consuming the response content"
@@ -94,10 +92,8 @@ def timed_recv_from_server(session, dest, byte_range):
     try:
         # headers are merged with the session ones, not overwritten.
         session.get(dest.url, headers=HTTP_GET_HEADERS, verify=dest.verify)
-    # NewConnectionError will be raised when shutting down.
-    except (requests.exceptions.ConnectionError,
-            requests.exceptions.ReadTimeout,
-            requests.exceptions.NewConnectionError) as e:
+    # Catch any `requests` exception, so that it can stored in the Result
+    except requests.exceptions.RequestException as e:
         log.debug(e)
         return False, e
     end_time = time.time()
diff --git a/sbws/lib/destination.py b/sbws/lib/destination.py
index e1be0bb..c0e6b03 100644
--- a/sbws/lib/destination.py
+++ b/sbws/lib/destination.py
@@ -76,11 +76,8 @@ def connect_to_destination_over_circuit(dest, circ_id, session, cont, max_dl):
         listener = stem_utils.attach_stream_to_circuit_listener(cont, circ_id)
         stem_utils.add_event_listener(cont, listener, EventType.STREAM)
         try:
-            # TODO:
-            # - What other exceptions can this throw?
             head = session.head(dest.url, verify=dest.verify)
-        except (requests.exceptions.ConnectionError,
-                requests.exceptions.ReadTimeout) as e:
+        except requests.exceptions.RequestException as e:
             dest.set_failure()
             return False, 'Could not connect to {} over circ {} {}: {}'.format(
                 dest.url, circ_id, stem_utils.circuit_str(cont, circ_id), e)





More information about the tor-commits mailing list