[tor-commits] [stem/master] Catch ORPort socket timeouts
atagar at torproject.org
atagar at torproject.org
Wed Jan 23 20:43:08 UTC 2019
commit 2e86567b0cbcae03ddf1bec335808cd51329c961
Author: Damian Johnson <atagar at torproject.org>
Date: Wed Jan 23 11:50:49 2019 -0800
Catch ORPort socket timeouts
Oops. I added a timeout attribute but completely forgot to catch the resulting
exceptions. Caught thanks to starlight...
https://trac.torproject.org/projects/tor/ticket/28961
Traceback (most recent call last):
File "../download_descriptor.py", line 133, in <module>
main()
File "../download_descriptor.py", line 115, in main
endpoints = [args.download_from],
File "/usr/local/lib/python3.7/site-packages/stem/descriptor/remote.py", line 485, in run
return list(self._run(suppress))
File "/usr/local/lib/python3.7/site-packages/stem/descriptor/remote.py", line 496, in _run
raise self.error
File "/usr/local/lib/python3.7/site-packages/stem/descriptor/remote.py", line 561, in _download_descriptors
self.content, self.reply_headers = _download_from_orport(endpoint, self.compression, self.resource)
File "/usr/local/lib/python3.7/site-packages/stem/descriptor/remote.py", line 962, in _download_from_orport
with relay.create_circuit() as circ:
File "/usr/local/lib/python3.7/site-packages/stem/client/__init__.py", line 207, in create_circuit
for cell in self._msg(create_fast_cell):
File "/usr/local/lib/python3.7/site-packages/stem/client/__init__.py", line 160, in _msg
response = self._orport.recv(timeout = 1)
File "/usr/local/lib/python3.7/site-packages/stem/socket.py", line 416, in recv
return self._recv(wrapped_recv)
File "/usr/local/lib/python3.7/site-packages/stem/socket.py", line 274, in _recv
return handler(my_socket, my_socket_file)
File "/usr/local/lib/python3.7/site-packages/stem/socket.py", line 410, in wrapped_recv
return s.recv()
File "/usr/local/lib/python3.7/ssl.py", line 1037, in recv
return self.read(buflen)
File "/usr/local/lib/python3.7/ssl.py", line 913, in read
return self._sslobj.read(len)
socket.timeout: The read operation timed out
Through experimentation I also managed to get the following too...
Traceback (most recent call last):
File "download_descriptor.py", line 131, in <module>
main()
File "download_descriptor.py", line 113, in main
endpoints = [args.download_from],
File "/home/atagar/Desktop/stem/stem/descriptor/remote.py", line 485, in run
return list(self._run(suppress))
File "/home/atagar/Desktop/stem/stem/descriptor/remote.py", line 496, in _run
raise self.error
ssl.SSLError: ('The read operation timed out',)
Unfortunately since this is an SSL socket (rather than a standard one) receive
calls are liable to raise exceptions from both modules making this a bit of a
whack-a-mole game (socket's docs are particularly bad about describing the
array of exceptions that might get raised).
---
stem/socket.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/stem/socket.py b/stem/socket.py
index 9290d6c6..80d29b83 100644
--- a/stem/socket.py
+++ b/stem/socket.py
@@ -408,7 +408,7 @@ class RelaySocket(BaseSocket):
try:
return s.recv()
- except ssl.SSLWantReadError:
+ except (socket.timeout, ssl.SSLError, ssl.SSLWantReadError):
return None
finally:
s.setblocking(1)
More information about the tor-commits
mailing list