Browse Source

Bug 1977: Ignore disconnect messages from the server while closing the connection

https://winscp.net/tracker/1977

Source commit: 7c31360a979917cfed687545d2e7b56c429190f1
Martin Prikryl 4 years ago
parent
commit
556633c71f
3 changed files with 12 additions and 3 deletions
  1. 10 2
      source/core/SecureShell.cpp
  2. 1 0
      source/core/SecureShell.h
  3. 1 1
      source/core/Terminal.cpp

+ 10 - 2
source/core/SecureShell.cpp

@@ -111,6 +111,7 @@ void __fastcall TSecureShell::ResetConnection()
     log_free(FLogCtx);
   }
   FLogCtx = NULL;
+  FClosed = false;
 }
 //---------------------------------------------------------------------------
 void __fastcall TSecureShell::ResetSessionInfo()
@@ -1555,8 +1556,14 @@ void __fastcall TSecureShell::PuttyFatalError(UnicodeString Error)
 {
   UnicodeString HelpKeyword;
   TranslateErrorMessage(Error, &HelpKeyword);
-
-  FatalError(Error, HelpKeyword);
+  if (!FClosed)
+  {
+    FatalError(Error, HelpKeyword);
+  }
+  else
+  {
+    LogEvent(FORMAT(L"Ignoring an error from the server while closing: %s", (Error)));
+  }
 }
 //---------------------------------------------------------------------------
 void __fastcall TSecureShell::FatalError(UnicodeString Error, UnicodeString HelpKeyword)
@@ -1713,6 +1720,7 @@ void __fastcall TSecureShell::Discard()
   bool WasActive = FActive;
   FActive = false;
   FOpened = false;
+  FClosed = true;
 
   if (WasActive)
   {

+ 1 - 0
source/core/SecureShell.h

@@ -47,6 +47,7 @@ private:
   bool FStoredPassphraseTried;
   int FSshVersion;
   bool FOpened;
+  bool FClosed;
   int FWaiting;
   bool FSimple;
   bool FNoConnectionResponse;

+ 1 - 1
source/core/Terminal.cpp

@@ -1335,7 +1335,7 @@ void __fastcall TTerminal::Open()
                   if (!FSecureShell->Active && !FTunnelError.IsEmpty())
                   {
                     // the only case where we expect this to happen (first in GUI, the latter in scripting)
-                    DebugAssert((E.Message == LoadStr(UNEXPECTED_CLOSE_ERROR)) || (E.Message == LoadStr(NET_TRANSL_CONN_ABORTED)));
+                    DebugAssert((E.Message == LoadStr(UNEXPECTED_CLOSE_ERROR)) || (E.Message == LoadStr(NET_TRANSL_CONN_ABORTED)) || (E.Message.Pos(LoadStr(NOT_CONNECTED)) > 0));
                     FatalError(&E, FMTLOAD(TUNNEL_ERROR, (FTunnelError)));
                   }
                   else