From 51f772d78e6894017eecfbb9978fbebd4f334976 Mon Sep 17 00:00:00 2001 From: Loren Eteval Date: Sat, 5 Aug 2023 11:32:52 +0800 Subject: [PATCH] Fix connect error reporting bug Signed-off-by: Loren Eteval --- Furious/Action/Connect.py | 63 +++++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 6 deletions(-) diff --git a/Furious/Action/Connect.py b/Furious/Action/Connect.py index 1e55252..11adf4d 100644 --- a/Furious/Action/Connect.py +++ b/Furious/Action/Connect.py @@ -64,6 +64,8 @@ class ConnectAction(Action): self.connectingFlag = False + self.disconnectReason = '' + # Note: The connection test is carried out item by item # from top to bottom. If any of these succeed, # connected action will be executed. @@ -94,6 +96,13 @@ class ConnectAction(Action): return self.disconnectAction( f'{XrayCore.name()}: {_("Invalid server configuration")}' ) + else: + self.coreRunning = False + self.disconnectReason = ( + f'{XrayCore.name()}: {_("Invalid server configuration")}' + ) + + return if exitcode == XrayCore.ExitCode.ServerStartFailure: if not self.isConnecting(): @@ -101,12 +110,24 @@ class ConnectAction(Action): return self.disconnectAction( f'{XrayCore.name()}: {_("Failed to start core")}' ) + else: + self.coreRunning = False + self.disconnectReason = ( + f'{XrayCore.name()}: {_("Failed to start core")}' + ) + + return if not self.isConnecting(): # Protect connecting action. Mandatory self.disconnectAction( f'{XrayCore.name()}: {_("Core terminated unexpectedly")}' ) + else: + self.coreRunning = False + self.disconnectReason = ( + f'{XrayCore.name()}: {_("Core terminated unexpectedly")}' + ) def HysteriaExitCallback(self, exitcode): if self.coreName: @@ -120,6 +141,13 @@ class ConnectAction(Action): return self.disconnectAction( f'{Hysteria.name()}: {_("Invalid server configuration")}' ) + else: + self.coreRunning = False + self.disconnectReason = ( + f'{Hysteria.name()}: {_("Invalid server configuration")}' + ) + + return if exitcode == Hysteria.ExitCode.RemoteNetworkError: if not self.isConnecting(): @@ -127,12 +155,24 @@ class ConnectAction(Action): return self.disconnectAction( f'{Hysteria.name()}: {_("Connection to server has been lost")}' ) + else: + self.coreRunning = False + self.disconnectReason = ( + f'{Hysteria.name()}: {_("Connection to server has been lost")}' + ) + + return if not self.isConnecting(): # Protect connecting action. Mandatory self.disconnectAction( f'{Hysteria.name()}: {_("Core terminated unexpectedly")}' ) + else: + self.coreRunning = False + self.disconnectReason = ( + f'{Hysteria.name()}: {_("Core terminated unexpectedly")}' + ) def stopCore(self): # Stop any potentially running core @@ -229,6 +269,8 @@ class ConnectAction(Action): # Accept new action self.setDisabledAction(False) + self.disconnectReason = '' + self.connectingFlag = False @property @@ -517,13 +559,16 @@ class ConnectAction(Action): f'{self.coreName}: connection test failed. {self.networkReply.errorString()}' ) - if self.testTime < len(self.testPool): + if self.testTime < len(self.testPool) and self.coreRunning: # Try next self.startConnectionTest(showRoutingChangedMessage) else: - self.disconnectAction( - f'{self.coreName}: {_("Connection test failed")}' - ) + if self.disconnectReason: + self.disconnectAction(self.disconnectReason) + else: + self.disconnectAction( + f'{self.coreName}: {_("Connection test failed")}' + ) else: logger.info(f'{self.coreName}: connection test success. Connected') @@ -626,8 +671,14 @@ class ConnectAction(Action): return if not self.coreRunning: - # No valid HTTP proxy endpoint / Core has exited. - # reset / disconnect has been called + # 1. No valid HTTP proxy endpoint. reset / disconnect has been called + + if self.isConnecting(): + # 2. Core has exited. disconnectReason must not be empty + assert self.disconnectReason + + self.disconnectAction(self.disconnectReason) + return try: