[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Recognize socket disconnections



commit b489fda9a2e91a62423ba81a73f0787f9486e29b
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Fri Jul 31 18:11:48 2020 -0700

    Recognize socket disconnections
    
    Unfortunately we can't differentiate socket disconnections from errors except
    by its message. Asyncio sockets use a different message so revising our check.
    
    This fixes the following RUN_SOCKET test...
    
      ======================================================================
      ERROR: test_send_disconnected
      ----------------------------------------------------------------------
      Traceback (most recent call last):
        File "/home/atagar/Desktop/stem/stem/socket.py", line 536, in _write_to_socket
          await writer.drain()
        File "/home/atagar/Python-3.7.0/Lib/asyncio/streams.py", line 348, in drain
          await self._protocol._drain_helper()
        File "/home/atagar/Python-3.7.0/Lib/asyncio/streams.py", line 202, in _drain_helper
          raise ConnectionResetError('Connection lost')
      ConnectionResetError: Connection lost
    
      During handling of the above exception, another exception occurred:
    
      Traceback (most recent call last):
        File "/home/atagar/Desktop/stem/test/require.py", line 75, in wrapped
          return func(self, *args, **kwargs)
        File "/home/atagar/Desktop/stem/stem/util/test_tools.py", line 701, in wrapper
          result = loop.run_until_complete(func(*args, **kwargs))
        File "/home/atagar/Python-3.7.0/Lib/asyncio/base_events.py", line 568, in run_until_complete
          return future.result()
        File "/home/atagar/Desktop/stem/test/integ/socket/control_socket.py", line 118, in test_send_disconnected
          await control_socket.send('blarg')
        File "/home/atagar/Desktop/stem/stem/socket.py", line 413, in send
          await self._send(message, send_message)
        File "/home/atagar/Desktop/stem/stem/socket.py", line 238, in _send
          await handler(self._writer, message)
        File "/home/atagar/Desktop/stem/stem/socket.py", line 525, in send_message
          await _write_to_socket(writer, message)
        File "/home/atagar/Desktop/stem/stem/socket.py", line 547, in _write_to_socket
          raise stem.SocketError(exc)
      stem.SocketError: Connection lost
---
 stem/socket.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/stem/socket.py b/stem/socket.py
index 90d8755b..d594f107 100644
--- a/stem/socket.py
+++ b/stem/socket.py
@@ -541,7 +541,7 @@ async def _write_to_socket(writer: asyncio.StreamWriter, message: Union[str, byt
     # distinguishing between failures from a disconnect verses other things.
     # Just accounting for known disconnection responses.
 
-    if str(exc) == '[Errno 32] Broken pipe':
+    if str(exc) == 'Connection lost':
       raise stem.SocketClosed(exc)
     else:
       raise stem.SocketError(exc)



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits