[tor-commits] [stem/master] launch_tor_with_config() raises an OSError if called too many times

atagar at torproject.org atagar at torproject.org
Sun Sep 14 23:20:32 UTC 2014


commit f2a4994175b9cb982beceb868133c51296482fc0
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Sep 14 16:19:17 2014 -0700

    launch_tor_with_config() raises an OSError if called too many times
    
    Issue caught by RSenet on...
    
      https://trac.torproject.org/projects/tor/ticket/13141
    
    We didn't close our torrc's file descriptor, causing an OSError if the function
    is called too many times.
---
 docs/change_log.rst |    1 +
 stem/process.py     |    3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/docs/change_log.rst b/docs/change_log.rst
index ff58d12..ff5b60d 100644
--- a/docs/change_log.rst
+++ b/docs/change_log.rst
@@ -46,6 +46,7 @@ The following are only available within Stem's `git repository
   * Added :func:`~stem.control.BaseController.connection_time` to the :class:`~stem.control.BaseController`
   * Changed :func:`~stem.control.Controller.get_microdescriptor`, :func:`~stem.control.Controller.get_server_descriptor`, and :func:`~stem.control.Controller.get_network_status` to get our own descriptor if no fingerprint or nickname is provided.
   * Added :class:`~stem.exit_policy.ExitPolicy` methods for more easily handling 'private' policies (the `default prefix <https://www.torproject.org/docs/tor-manual.html.en#ExitPolicyRejectPrivate>`_) and the defaultly appended suffix. This includes :func:`~stem.exit_policy.ExitPolicy.has_private`, :func:`~stem.exit_policy.ExitPolicy.strip_private`, :func:`~stem.exit_policy.ExitPolicy.has_default`, and :func:`~stem.exit_policy.ExitPolicy.strip_default` :class:`~stem.exit_policy.ExitPolicy` methods in addition to :func:`~stem.exit_policy.ExitPolicyRule.is_private` and :func:`~stem.exit_policy.ExitPolicyRule.is_default` for the :class:`~stem.exit_policy.ExitPolicyRule`. (:trac:`10107`)
+  * :func:`~stem.process.launch_tor_with_config` could cause a "Too many open files" OSError if called too many times (:trac:`13141`)
 
  * **Descriptors**
 
diff --git a/stem/process.py b/stem/process.py
index 2886270..af66cce 100644
--- a/stem/process.py
+++ b/stem/process.py
@@ -227,7 +227,7 @@ def launch_tor_with_config(config, tor_cmd = 'tor', completion_percent = 100, in
     if not has_stdout:
       config['Log'].append('NOTICE stdout')
 
-  torrc_path = tempfile.mkstemp(prefix = 'torrc-', text = True)[1]
+  torrc_descriptor, torrc_path = tempfile.mkstemp(prefix = 'torrc-', text = True)
 
   try:
     with open(torrc_path, 'w') as torrc_file:
@@ -244,6 +244,7 @@ def launch_tor_with_config(config, tor_cmd = 'tor', completion_percent = 100, in
     return launch_tor(tor_cmd, args, torrc_path, completion_percent, init_msg_handler, timeout, take_ownership)
   finally:
     try:
+      os.close(torrc_descriptor)
       os.remove(torrc_path)
     except:
       pass



More information about the tor-commits mailing list