Browse Source

Bug fix: Session.GetFile can fail, if the server responds too quickly

Source commit: 2d3b1690a7bb44de6bcfbcf45cd6ba099d381363
Martin Prikryl 4 years ago
parent
commit
c098c23fad
1 changed files with 13 additions and 2 deletions
  1. 13 2
      dotnet/Session.cs

+ 13 - 2
dotnet/Session.cs

@@ -1090,6 +1090,11 @@ namespace WinSCP
                     operationResultGuard = RegisterOperationResult(result);
                     progressHandler = CreateProgressHandler();
 
+                    if (_throwStdOut)
+                    {
+                        throw Logger.WriteException(new InvalidOperationException());
+                    }
+                    _throwStdOut = true;
                     bool downloadFound;
                     try
                     {
@@ -1102,6 +1107,10 @@ namespace WinSCP
                     {
                         downloadFound = true;
                     }
+                    finally
+                    {
+                        _throwStdOut = false;
+                    }
                     if (downloadFound)
                     {
                         callstackAndLock.DisarmLock();
@@ -2277,9 +2286,10 @@ namespace WinSCP
                 throw Logger.WriteException(new SessionLocalException(this, "Aborted."));
             }
 
-            if ((_process.StdOut != null) && _process.StdOut.ReadAvailable(1))
+            if (_throwStdOut && (_process.StdOut != null) && _process.StdOut.ReadAvailable(1))
             {
-                throw new StdOutException();
+                // This is here to return from GetFile asap (?)
+                throw Logger.WriteException(new StdOutException());
             }
         }
 
@@ -2789,5 +2799,6 @@ namespace WinSCP
         private bool _ignoreFailed;
         private TimeSpan _sessionTimeout;
         private QueryReceivedEventHandler _queryReceived;
+        private bool _throwStdOut;
     }
 }