From 8a72ae76fd171ebe3f6f4e38806600a2b6818e7e Mon Sep 17 00:00:00 2001 From: SimplifiedPrivacy Date: Thu, 22 Oct 2026 21:49:24 -0400 Subject: [PATCH] Fixed a bug in teardown of failed attempt, to properly kill firewall --- .../encrypted_proxy/singbox_runner.py | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/core/services/networking/systemwide/encrypted_proxy/singbox_runner.py b/core/services/networking/systemwide/encrypted_proxy/singbox_runner.py index 2d27199..1fe0be1 100644 --- a/core/services/networking/systemwide/encrypted_proxy/singbox_runner.py +++ b/core/services/networking/systemwide/encrypted_proxy/singbox_runner.py @@ -55,15 +55,15 @@ def verify_connection_integrity(connection_observer: ConnectionObserver, server_ return Result(valid=True, data=observed_ip) -def teardown_failed_connection(current_state: SystemState) -> None: - """Performs a full cleanup: closes the interface and dissolves system state.""" - logger.info("Performing full teardown of failed connection...") +# def teardown_failed_connection(current_state: SystemState) -> None: +# """Performs a full cleanup: closes the interface and dissolves system state.""" +# logger.info("Performing full teardown of failed connection...") - closed = orchestrate_closing(current_state=current_state, interface=Constants.SINGBOX_TUN_IF) +# closed = orchestrate_closing(current_state=current_state, interface=Constants.SINGBOX_TUN_IF) - if closed.valid: - logger.info("Closed singbox. Performing redundant state removal...") - SystemStateController.dissolve() +# if closed.valid: +# logger.info("Closed singbox. Performing redundant state removal...") +# SystemStateController.dissolve() def confirm_proxy_started(protocol_choice: str) -> bool: @@ -169,13 +169,14 @@ def _attempt_start_with_retry(profile_id: int, quantity_of_attempts: int = 2) -> -def end_singbox() -> Result: +def end_singbox(current_state: Optional[SystemState] = None) -> Result: """Orchestrate closing singbox's process, firewall, dns, and json state.""" logger.info("Starting end_singbox") # ======== JSON STATE ======== - current_state = SystemState.get() + if not current_state: + current_state = SystemStateController.get() # 1. WireGuard Cleanup. In case, it was a different protocol. if current_state and get_protocol_enum(current_state.profile_id) == ProtocolChoice.WIREGUARD: @@ -337,14 +338,14 @@ def start_singbox( net_result = apply_network_settings(current_state, server_ip, connection_observer) if not net_result.valid: logger.error(f"Network Config Failed: {net_result.message}") - teardown_failed_connection(current_state) # <--- Full teardown + end_singbox(current_state) # <--- Full teardown return net_result # 6. Final IP Integrity Check validation = verify_connection_integrity(connection_observer, server_ip) if not validation.valid: logger.error(validation.message) - teardown_failed_connection(current_state) # <--- Full teardown + end_singbox(current_state) # <--- Full teardown if validation.error_type == ResultError.LEAK_ISSUE and connection_observer: connection_observer.notify("connecting", "Failed Connection! Test showed leak!") return validation