#26056 closed enhancement (implemented)

Stem should optionally timeout when building circuits

Reported by: pastly Owned by: atagar
Priority: Medium Milestone:
Component: Archived/Stem Version:
Severity: Normal Keywords: controller
Cc: Actual Points:
Parent ID: Points:
Reviewer: Sponsor:


I recently found out that CircuitBuildTimeout 10\nLearnCircuitBuildTimeout 0 doesn't always make your circuit build attempts timeout after 10 seconds. In an attemp to avoid repeating myself, I think the commit message[0] has a good summary of why.

I would find it immensely useful if stem could optionally take a timeout on its new_circuit function that would raise an exception when the timeout is hit. For completeness, I imagine new_circuit's sibling functions like extend_circuit should probably also take a timeout.

For the time being, I've implemented a work around in sbws. I am providing the commit that makes the change in case it would be helpful for doing something similar in stem. I think it's messy, gross, and probably needlessly complicated. Do with it what you will :) I hope someday soon I can burn it with fire.

[0]: https://github.com/pastly/simple-bw-scanner/commit/dc63ad05bb78bd81d68046688e6f08a717150b9f

Child Tickets

Change History (4)

comment:1 Changed 21 months ago by atagar

comment:2 Changed 21 months ago by atagar

Keywords: controller added

comment:3 Changed 21 months ago by pastly

Oh man this is great. It felt good deleting all the code I just wrote.

One thing though: it always times out immediately in the first raise stem.Timeout(...). I think time_left is calculated incorrectly and should be done like this.

(venv-editable) [matt@zen stem]$ git diff
diff --git a/stem/control.py b/stem/control.py
index 244aed0b..a9d33749 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -4025,7 +4025,7 @@ def _get_with_timeout(event_queue, timeout, start_time):
   if timeout:
-    time_left = time.time() - start_time - timeout
+    time_left = timeout - (time.time() - start_time)
     if time_left <= 0:
       raise stem.Timeout('Reached our %0.1f second timeout' % timeout)

comment:4 Changed 21 months ago by atagar

Resolution: implemented
Status: newclosed

Oh oops! Great catch, thanks pastly. Fix pushed.

Note: See TracTickets for help on using tickets.