[tor-commits] [stem/master] Disconnected sockets raise OSErrors

atagar at torproject.org atagar at torproject.org
Sun Jan 5 21:39:28 UTC 2020


commit 7e1234c39f6a2e9f894d3c8e24a46e2921961acb
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Jan 5 12:40:56 2020 -0800

    Disconnected sockets raise OSErrors
    
    Dropping exception normalization has caused our tests to fail with...
    
      ======================================================================
      ERROR: test_disconnected_socket
      ----------------------------------------------------------------------
      Traceback (most recent call last):
        File "/home/atagar/Desktop/stem/test/unit/response/control_message.py", line 169, in test_disconnected_socket
          self.assertRaises(stem.SocketClosed, stem.socket.recv_message, control_socket_file)
        File "/home/atagar/Python-3.7.0/Lib/unittest/case.py", line 743, in assertRaises
          return context.handle('assertRaises', args, kwargs)
        File "/home/atagar/Python-3.7.0/Lib/unittest/case.py", line 178, in handle
          callable_obj(*args, **kwargs)
        File "/home/atagar/Desktop/stem/stem/socket.py", line 665, in recv_message
          line = control_file.readline()
        File "/home/atagar/Python-3.7.0/Lib/socket.py", line 589, in readinto
          return self._sock.recv_into(b)
      OSError: [Errno 107] Transport endpoint is not connected
    
    Rather than catching socket.error as we used to narrowing this to OSErrors. If
    other socket error subclasses come up in practice we'll go back to the parent
    class.
---
 stem/socket.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/stem/socket.py b/stem/socket.py
index a62bb6b3..4ab534b8 100644
--- a/stem/socket.py
+++ b/stem/socket.py
@@ -669,8 +669,12 @@ def recv_message(control_file, arrived_at = None):
 
       log.info(ERROR_MSG % ('SocketClosed', 'socket file has been closed'))
       raise stem.SocketClosed('socket file has been closed')
-    except ValueError as exc:
-      # when disconnected this errors with 'I/O operation on closed file'
+    except (OSError, ValueError) as exc:
+      # when disconnected this errors with...
+      #
+      #   * ValueError: I/O operation on closed file
+      #   * OSError: [Errno 107] Transport endpoint is not connected
+      #   * OSError: [Errno 9] Bad file descriptor
 
       log.info(ERROR_MSG % ('SocketClosed', 'received exception "%s"' % exc))
       raise stem.SocketClosed(exc)





More information about the tor-commits mailing list