From 6dc6b0af48239be78ea74a0b4a692231a0816949 Mon Sep 17 00:00:00 2001 From: codeking Date: Sun, 18 Jan 2026 21:13:53 +0100 Subject: [PATCH] Improve support for stateful Tor sessions --- core/Constants.py | 1 + core/controllers/ConnectionController.py | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/core/Constants.py b/core/Constants.py index 860dae1..f61e9ce 100644 --- a/core/Constants.py +++ b/core/Constants.py @@ -51,3 +51,4 @@ class Constants: HV_TOR_CONTROL_SOCKET_PATH: Final[str] = f'{HV_TOR_SESSION_STATE_HOME}/tor.sock' HV_TOR_PROCESS_IDENTIFIER_PATH: Final[str] = f'{HV_TOR_SESSION_STATE_HOME}/tor.pid' + HV_TOR_INSTANCE_LOCK_PATH: Final[str] = f'{HV_TOR_SESSION_STATE_HOME}/lock' diff --git a/core/controllers/ConnectionController.py b/core/controllers/ConnectionController.py index 6ab2a24..356989b 100644 --- a/core/controllers/ConnectionController.py +++ b/core/controllers/ConnectionController.py @@ -289,6 +289,8 @@ class ConnectionController: controller.authenticate() except (FileNotFoundError, stem.SocketError, TypeError, IndexError): + + ConnectionController.terminate_tor_connection() raise TorServiceInitializationError('The dedicated Tor service could not be initialized.') for session_state in SessionStateController.all(): @@ -299,8 +301,9 @@ class ConnectionController: @staticmethod def terminate_tor_connection(): - process_identifier_file = Path(Constants.HV_TOR_PROCESS_IDENTIFIER_PATH) control_socket_file = Path(Constants.HV_TOR_CONTROL_SOCKET_PATH) + process_identifier_file = Path(Constants.HV_TOR_PROCESS_IDENTIFIER_PATH) + instance_lock_file = Path(Constants.HV_TOR_INSTANCE_LOCK_PATH) try: process_identifier = int(process_identifier_file.read_text().strip()) @@ -319,8 +322,9 @@ class ConnectionController: except psutil.NoSuchProcess: pass - process_identifier_file.unlink(missing_ok=True) control_socket_file.unlink(missing_ok=True) + process_identifier_file.unlink(missing_ok=True) + instance_lock_file.unlink(missing_ok=True) @staticmethod def establish_wireguard_session_connection(profile: SessionProfile, session_directory: str, port_number: int):