From eaf61c280ae980c1b73956aad48e62da2d4a1656 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Tue, 1 Dec 2020 16:24:10 -0600 Subject: [PATCH] fixed subprocesspow not exiting on wsl --- src/httpapi/miscclientapi/endpoints.py | 4 ++++ src/lan/client/__init__.py | 4 ++++ src/netcontroller/torcontrol/__init__.py | 2 +- src/onionrcommands/daemonlaunch/__init__.py | 19 +++++++++++-------- src/onionrproofs/subprocesspow.py | 4 ++-- src/vanityonionr/__init__.py | 4 ++-- static-data/default_config.json | 2 +- 7 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/httpapi/miscclientapi/endpoints.py b/src/httpapi/miscclientapi/endpoints.py index 86270865..715e8c43 100644 --- a/src/httpapi/miscclientapi/endpoints.py +++ b/src/httpapi/miscclientapi/endpoints.py @@ -66,6 +66,10 @@ class PrivateEndpoints: return send_from_directory(config.get('www.private.path', 'static-data/www/private/'), path) + @private_endpoints_bp.route('/getpid') + def get_pid(): + return Response(str(os.getpid())) + @private_endpoints_bp.route('/hitcount') def get_hit_count(): return Response(str(client_api.publicAPI.hitCount)) diff --git a/src/lan/client/__init__.py b/src/lan/client/__init__.py index 5c4f108e..b2626b63 100644 --- a/src/lan/client/__init__.py +++ b/src/lan/client/__init__.py @@ -44,6 +44,10 @@ def _lan_work(peer: LANIP): url + f'get/{block}', stream=True).raw.read(6000000)) except onionrexceptions.InvalidMetadata: logger.warn(f"Could not get {block} from lan peer") + except onionrexceptions.InvalidProof: + logger.warn( + f"Invalid proof for {block} from lan peer {peer}", terminal=True) + break for port in ports: try: diff --git a/src/netcontroller/torcontrol/__init__.py b/src/netcontroller/torcontrol/__init__.py index 81f6fb9a..d1b8b3c9 100644 --- a/src/netcontroller/torcontrol/__init__.py +++ b/src/netcontroller/torcontrol/__init__.py @@ -120,7 +120,7 @@ class NetController: tor_pid_file.write(str(tor.pid)) multiprocessing.Process(target=watchdog.watchdog, - args=[os.getpid(), tor.pid]).start() + args=[os.getpid(), tor.pid], daemon=True).start() logger.info('Finished starting Tor.', terminal=True) diff --git a/src/onionrcommands/daemonlaunch/__init__.py b/src/onionrcommands/daemonlaunch/__init__.py index 193eb54e..2ea25726 100755 --- a/src/onionrcommands/daemonlaunch/__init__.py +++ b/src/onionrcommands/daemonlaunch/__init__.py @@ -129,9 +129,17 @@ def daemon(): """Start Onionr's primary threads for communicator, API server, node, and LAN.""" def _handle_sig_term(signum, frame): - logger.info( - "Received sigterm, shutting down gracefully", terminal=True) - localcommand.local_command('/shutdownclean') + pid = str(os.getpid()) + main_pid = localcommand.local_command('/getpid') + #logger.info(main_pid, terminal=True) + if main_pid and main_pid == pid: + logger.info( + f"Received sigterm, shutting down gracefully. PID: {pid}", terminal=True) + localcommand.local_command('/shutdownclean') + else: + logger.info( + f"Recieved sigterm in child process or fork, exiting. PID: {pid}") + sys.exit(0) signal.signal(signal.SIGTERM, _handle_sig_term) # Determine if Onionr is in offline mode. @@ -233,11 +241,6 @@ def daemon(): filenuke.nuke.clean_tree(identifyhome.identify_home()) -def _ignore_sigint(sig, frame): # pylint: disable=W0612,W0613 - """Space intentionally left blank.""" - return - - def start(override: bool = False): """If no lock file, make one and start onionr. diff --git a/src/onionrproofs/subprocesspow.py b/src/onionrproofs/subprocesspow.py index 750bddec..092639fd 100755 --- a/src/onionrproofs/subprocesspow.py +++ b/src/onionrproofs/subprocesspow.py @@ -94,7 +94,7 @@ class SubprocessPOW: parent_conn, child_conn = Pipe() p = Process(target=self.do_pow, args=(child_conn,), daemon=True) p.start() - p.join() + #p.join() payload = None try: while True: @@ -105,7 +105,7 @@ class SubprocessPOW: except KeyboardInterrupt: pass finally: - parent_conn.send('shutdown') + p.terminate() self.payload = payload def do_pow(self, pipe): diff --git a/src/vanityonionr/__init__.py b/src/vanityonionr/__init__.py index ab797dd0..7be6abcd 100644 --- a/src/vanityonionr/__init__.py +++ b/src/vanityonionr/__init__.py @@ -48,7 +48,7 @@ def find_vanity_mnemonic(start_words: str, queue): def _start(start_words, obj): done = False q = Queue() - p = Process(target=find_vanity_mnemonic, args=[start_words, q]) + p = Process(target=find_vanity_mnemonic, args=[start_words, q], daemon=True) p.daemon = True p.start() rec = None @@ -68,7 +68,7 @@ def handler(start_words: str): obj = lambda test: None obj.done = False for x in range(multiprocessing.cpu_count()): - threading.Thread(target=_start, args=[start_words, obj]).start() + threading.Thread(target=_start, args=[start_words, obj], daemon=True).start() while not obj.done: time.sleep(1) return obj.result diff --git a/static-data/default_config.json b/static-data/default_config.json index 11973b86..69b485fc 100755 --- a/static-data/default_config.json +++ b/static-data/default_config.json @@ -71,7 +71,7 @@ "tor": true }, "ui": { - "animated_background": true, + "animated_background": false, "public_remote_enabled": false, "public_remote_hosts": [], "theme": "dark"