Fixed Bug #21135 - Deadlock in WebConnectionStream
authorFritz Elfert <fritz@fritz-elfert.de>
Fri, 11 Jul 2014 17:20:11 +0000 (19:20 +0200)
committerFritz Elfert <fritz@fritz-elfert.de>
Fri, 11 Jul 2014 17:20:11 +0000 (19:20 +0200)
mcs/class/System/System.Net/WebConnectionStream.cs

index b946654f329dfbf3bb9e78bfce8161dde8730c83..72977c4ce70726e8dde5e717da86047343e34111 100644 (file)
@@ -234,7 +234,8 @@ namespace System.Net
                                return;
                        }
 
-                       pending.WaitOne ();
+                       if (!pending.WaitOne (ReadTimeout))
+                               throw new WebException ("The operation has timed out.", WebExceptionStatus.Timeout);
                        lock (locker) {
                                if (totalRead >= contentLength)
                                        return;
@@ -592,6 +593,14 @@ namespace System.Net
                        if (result.EndCalled)
                                return;
 
+                       if (sendChunked) {
+                               lock (locker) {
+                                       pendingWrites--;
+                                       if (pendingWrites <= 0)
+                                               pending.Set ();
+                               }
+                       }
+
                        result.EndCalled = true;
                        if (result.AsyncWriteAll) {
                                result.WaitUntilComplete ();
@@ -605,14 +614,6 @@ namespace System.Net
 
                        if (result.GotException)
                                throw result.Exception;
-
-                       if (sendChunked) {
-                               lock (locker) {
-                                       pendingWrites--;
-                                       if (pendingWrites == 0)
-                                               pending.Set ();
-                               }
-                       }
                }
                
                public override void Write (byte [] buffer, int offset, int size)
@@ -761,7 +762,9 @@ namespace System.Net
                                if (disposed)
                                        return;
                                disposed = true;
-                               pending.WaitOne ();
+                               if (!pending.WaitOne (WriteTimeout)) {
+                                       throw new WebException ("The operation has timed out.", WebExceptionStatus.Timeout);
+                               }
                                byte [] chunk = Encoding.ASCII.GetBytes ("0\r\n\r\n");
                                string err_msg = null;
                                cnc.Write (request, chunk, 0, chunk.Length, ref err_msg);