[tor-bugs] #9862 [Stem]: Tor hangs if you ask it to open too many ORPorts

Tor Bug Tracker & Wiki blackhole at torproject.org
Wed Oct 16 01:38:42 UTC 2013


#9862: Tor hangs if you ask it to open too many ORPorts
------------------------+--------------------------------
     Reporter:  zwol    |      Owner:  atagar
         Type:  defect  |     Status:  needs_information
     Priority:  normal  |  Milestone:  Tor: 0.2.5.x-final
    Component:  Stem    |    Version:  Tor: 0.2.4.17-rc
   Resolution:          |   Keywords:  tor-relay
Actual Points:          |  Parent ID:
       Points:          |
------------------------+--------------------------------

Comment (by zwol):

 > waiting for the answer to "If you call `tor_process.stdout.close()` does
 this still manifest?"

 I'm sorry - to me, that so obviously won't work that I didn't even
 register it as a question.  If you do that, the Tor process will get a
 `SIGPIPE` and crash the very next time it writes to its stdout (resp.
 stderr).

 A dedicated thread calling `communicate()` is also a bad idea, for a
 different reason: that will accumulate all of the log messages in memory
 until the Tor process eventually exits.  For my use case, that could be
 weeks, and megabytes of notices.  (Probably not ''many'' megabytes, but
 I'm already struggling with the memory usage of this controller; every
 little bit helps.)

 This is my current workaround:

 {{{
 class PipeDrainer(threading.Thread):
     """Read and discard all data from a pipe.  Exits when the pipe is
 closed."""
     def __init__(self, fp):
         threading.Thread.__init__(self)
         self.fp = fp

     def run(self):
         try:
             while len(self.fp.read(8192)) > 0:
                 pass
         except:
             pass
         self.fp.close()

 # ...

             self.process = stem.process.launch_tor_with_config(config={
 ... },
                                take_ownership=True)
             self.stdout_drainer = PipeDrainer(self.process.stdout)
             self.stdout_drainer.start()
             self.stderr_drainer = PipeDrainer(self.process.stderr)
             self.stderr_drainer.start()
 }}}

-- 
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/9862#comment:13>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online


More information about the tor-bugs mailing list