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

[tor-commits] [stem/master] Timeout stalled queries and installation



commit a331ee334b5fa6ffcf5895a30c0f81e9ef7a2c13
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sun Aug 23 16:43:35 2020 -0700

    Timeout stalled queries and installation
    
    Couple good timeout suggestions from...
    
      https://github.com/torproject/stem/issues/61
---
 stem/control.py            | 7 ++++++-
 test/integ/installation.py | 8 +++++++-
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/stem/control.py b/stem/control.py
index 7578f2b5..79d5881d 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -360,6 +360,7 @@ IMMUTABLE_CONFIG_OPTIONS = set(map(stem.util.str_tools._to_unicode, map(str.lowe
 ))))
 
 LOG_CACHE_FETCHES = True  # provide trace level logging for cache hits
+MSG_TIMEOUT = 5  # seconds to await a response from tor
 
 # Configuration options that are fetched by a special key. The keys are
 # lowercase to make case insensitive lookups easier.
@@ -693,7 +694,11 @@ class BaseController(Synchronous):
 
       try:
         await self._socket.send(message)
-        response = await self._reply_queue.get()
+
+        try:
+          response = await asyncio.wait_for(self._reply_queue.get(), MSG_TIMEOUT)
+        except asyncio.TimeoutError:
+          raise stem.ControllerError('%s failed to receive a reply within %i seconds' % (message, MSG_TIMEOUT))
 
         # If the message we received back had an exception then re-raise it to the
         # caller. Otherwise return the response.
diff --git a/test/integ/installation.py b/test/integ/installation.py
index 57618cc2..d78cdc2f 100644
--- a/test/integ/installation.py
+++ b/test/integ/installation.py
@@ -18,6 +18,7 @@ import test
 
 from stem.util.test_tools import asynchronous
 
+INSTALLATION_TIMEOUT = 20  # usually takes ~5s
 BASE_INSTALL_PATH = '/tmp/stem_test'
 PYTHON_EXE = sys.executable if sys.executable else 'python'
 INSTALL_MISMATCH_MSG = "Running 'python setup.py sdist' doesn't match our git contents in the following way. The manifest in our setup.py may need to be updated...\n\n"
@@ -131,8 +132,13 @@ class TestInstallation(unittest.TestCase):
     meant to test that our MANIFEST.in is up to date.
     """
 
+    started_at = time.time()
+
     while stem.util.system.is_running(dependency_pid):
-      time.sleep(0.1)  # we need to run these tests serially
+      if time.time() > started_at + INSTALLATION_TIMEOUT:
+        raise AssertionError('Stem failed to install within %i seconds' % INSTALLATION_TIMEOUT)
+
+      time.sleep(0.1)  # these tests must run serially
 
     git_dir = os.path.join(test.STEM_BASE, '.git')
 

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