Browse Source

Make all chutney tors exit when tools/test-network.sh exits

Fixes #20409, as long as chutney and tools/test-network.sh do not hang.
(Hangs shouldn't happen, if they do, it's a separate bug.)
teor 7 years ago
parent
commit
5adda26c1b
4 changed files with 38 additions and 1 deletions
  1. 5 0
      README
  2. 20 1
      lib/chutney/TorNet.py
  3. 9 0
      tools/test-network.sh
  4. 4 0
      torrc_templates/common.i

+ 5 - 0
README

@@ -57,6 +57,7 @@ Warning Options:
   --only-warnings    CHUTNEY_WARNINGS_ONLY=true
 
 Expert Options:
+  --controlling-pid  CHUTNEY_CONTROLLING_PID
   --coverage         USE_COVERAGE_BINARY=true
   --net-dir          CHUTNEY_DATA_DIR
   --dry-run          NETWORK_DRY_RUN=true
@@ -125,6 +126,10 @@ Waiting for the network:
   after verifying, then exits (default: immediately). If CHUTNEY_STOP_TIME is
   negative, the script leaves the network running, and exits after verifying.
 
+  If none of these options are negative, test-network.sh tells the tor
+  processes to exit after it exits, using CHUTNEY_CONTROLLING_PID. To disable
+  this functionality, set CHUTNEY_CONTROLLING_PID to 1 or less.
+
 Changing the network address:
 
    Chutney defaults to binding to localhost. To change the IPv4 bind address,

+ 20 - 1
lib/chutney/TorNet.py

@@ -752,6 +752,10 @@ DEFAULTS = {
     'bootstrap_time': int(os.environ.get('CHUTNEY_BOOTSTRAP_TIME',
                                          os.environ.get('BOOTSTRAP_TIME',
                                                         60))),
+    # the PID of the controlling script (for __OwningControllerProcess)
+    'controlling_pid': (int(os.environ.get('CHUTNEY_CONTROLLING_PID', 0))
+                        if 'CHUTNEY_CONTROLLING_PID' in os.environ
+                        else None),
 }
 
 
@@ -770,7 +774,7 @@ class TorEnviron(chutney.Templating.Environ):
           torrc_template_path: path to chutney torrc_templates directory
           hs_hostname: the hostname of the key generated by a hidden service
           owning_controller_process: the __OwningControllerProcess torrc line,
-             or an empty string if tor should continue after the script exits
+             disabled if tor should continue after the script exits
 
        Environment fields used:
           nodenum: chutney's internal node number for the node
@@ -848,6 +852,21 @@ class TorEnviron(chutney.Templating.Environ):
                       (my['nick'], e.errno, e.strerror, hs_hostname_file))
         return my['hs-hostname']
 
+    def _get_owning_controller_process(self, my):
+        cpid = my['controlling_pid']
+        if cpid is None:
+            cpid = 0
+        ocp_line = ('__OwningControllerProcess %d' % (cpid))
+        # if we want to leave the network running, or controlling_pid is 1
+        # (or invalid)
+        if (os.environ.get('CHUTNEY_START_TIME', 0) < 0 or
+            os.environ.get('CHUTNEY_BOOTSTRAP_TIME', 0) < 0 or
+            os.environ.get('CHUTNEY_STOP_TIME', 0) < 0 or
+            cpid <= 1):
+            return '#' + ocp_line
+        else:
+            return ocp_line
+
 
 class Network(object):
 

+ 9 - 0
tools/test-network.sh

@@ -9,6 +9,9 @@ myname=$(basename "$0")
 export CHUTNEY_WARNINGS_IGNORE_EXPECTED=${CHUTNEY_WARNINGS_IGNORE_EXPECTED:-true}
 export CHUTNEY_WARNINGS_SUMMARY=${CHUTNEY_WARNINGS_SUMMARY:-true}
 
+# default to exiting when this script exits
+export CHUTNEY_CONTROLLING_PID=${CHUTNEY_CONTROLLING_PID:-$$}
+
 # what we say when we fail
 UPDATE_YOUR_CHUTNEY="Please update your chutney using 'git pull'."
 
@@ -60,6 +63,12 @@ do
       export CHUTNEY_STOP_TIME="$2"
       shift
     ;;
+    # If all of the CHUTNEY_*_TIME options are positive, chutney will ask tor
+    # to exit when this PID exits. Set to 1 or lower to disable.
+    --controlling-pid)
+      export CHUTNEY_CONTROLLING_PID="$2"
+      shift
+    ;;
     # Environmental variables used by chutney verify performance tests
     # Send this many bytes per client connection (10 KBytes)
     --data|--data-bytes|--data-byte|--bytes|--byte)

+ 4 - 0
torrc_templates/common.i

@@ -45,6 +45,10 @@ ControlPort $controlport
 ControlSocket ${dir}/control
 CookieAuthentication 1
 PidFile ${dir}/pid
+# Ask all child tor processes to exit when chutney's test-network.sh exits
+# (if the CHUTNEY_*_TIME options leave the network running, this option is
+# disabled)
+${owning_controller_process}
 
 Log notice file ${dir}/notice.log
 Log info file ${dir}/info.log