Browse Source

Bug 1683: Failure when .NET assembly timeouts waiting for WinSCP process

https://winscp.net/tracker/1683

Source commit: 481861f7a70e83540accc30718eb99ae81bf8442
Martin Prikryl 7 years ago
parent
commit
01f7c61d51
2 changed files with 32 additions and 17 deletions
  1. 1 0
      dotnet/Session.cs
  2. 31 17
      dotnet/internal/SessionLogReader.cs

+ 1 - 0
dotnet/Session.cs

@@ -1762,6 +1762,7 @@ namespace WinSCP
                 {
                     message += " - " + additional;
                 }
+                _logReader.SetTimeouted();
                 throw Logger.WriteException(new TimeoutException(message));
             }
 

+ 31 - 17
dotnet/internal/SessionLogReader.cs

@@ -15,6 +15,11 @@ namespace WinSCP
             _position = 0;
         }
 
+        public void SetTimeouted()
+        {
+            _timeouted = true;
+        }
+
         public override void Dispose()
         {
             using (Session.Logger.CreateCallstack())
@@ -46,32 +51,40 @@ namespace WinSCP
             using (Session.Logger.CreateCallstack())
             {
                 bool result;
-                bool retry;
-
-                do
+                if (_timeouted)
                 {
-                    result = DoRead();
-
-                    retry = false;
+                    Session.Logger.WriteLine("Not reading, session has timed out");
+                    result = false;
+                }
+                else
+                {
+                    bool retry;
 
-                    if (result &&
-                        IsNonEmptyElement("failure"))
+                    do
                     {
-                        SessionRemoteException e = SessionRemoteException.ReadFailure(this);
+                        result = DoRead();
 
-                        Session.RaiseFailed(e);
+                        retry = false;
 
-                        if ((flags & LogReadFlags.ThrowFailures) == 0)
-                        {
-                            retry = true;
-                        }
-                        else
+                        if (result &&
+                            IsNonEmptyElement("failure"))
                         {
-                            throw Session.Logger.WriteException(e);
+                            SessionRemoteException e = SessionRemoteException.ReadFailure(this);
+
+                            Session.RaiseFailed(e);
+
+                            if ((flags & LogReadFlags.ThrowFailures) == 0)
+                            {
+                                retry = true;
+                            }
+                            else
+                            {
+                                throw Session.Logger.WriteException(e);
+                            }
                         }
                     }
+                    while (retry);
                 }
-                while (retry);
 
                 return result;
             }
@@ -246,5 +259,6 @@ namespace WinSCP
         private PatientFileStream _stream;
         private bool _closed;
         private string _logged;
+        private bool _timeouted;
     }
 }