Browse Source

Issue 2258 – Hang when prompt pops up while SFTP session is being reconnected

https://winscp.net/tracker/2258

Source commit: 126372924b17f136a986914a46d62a3a46362971
Martin Prikryl 1 năm trước cách đây
mục cha
commit
1189b13e1f
1 tập tin đã thay đổi với 20 bổ sung8 xóa
  1. 20 8
      source/core/Queue.cpp

+ 20 - 8
source/core/Queue.cpp

@@ -2526,16 +2526,28 @@ void __fastcall TTerminalThread::Cancel()
 //---------------------------------------------------------------------------
 void __fastcall TTerminalThread::Idle()
 {
-  TGuard Guard(FSection);
-  // only when running user action already,
-  // so that the exception is caught, saved and actually
-  // passed back into the terminal thread, saved again
-  // and passed back to us
-  if ((FUserAction != NULL) && (FIdleException != NULL))
+  // If user action is needed during Idle() call from TTerminalThread::WaitForUserAction
+  // (e.g. when disconnect is detected and session get reconnected)
+  // unconditional Enter() here would deadlock.
+  if (FSection->TryEnter())
   {
-    Rethrow(FIdleException);
+    try
+    {
+      // only when running user action already,
+      // so that the exception is caught, saved and actually
+      // passed back into the terminal thread, saved again
+      // and passed back to us
+      if ((FUserAction != NULL) && (FIdleException != NULL))
+      {
+        Rethrow(FIdleException);
+      }
+      FPendingIdle = true;
+    }
+    __finally
+    {
+      FSection->Release();
+    }
   }
-  FPendingIdle = true;
 }
 //---------------------------------------------------------------------------
 void __fastcall TTerminalThread::TerminalOpen()