Merge pull request #2373 from akoeplinger/servicemodel-tcpreplychannel-race
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Channels.Http / HttpReplyChannel.cs
index 5bc1c4dc3b38c8fedb1b2eefe43514b9f840572e..098b622aa836a1ca86cba5c3fd4e1872fbc0aee8 100644 (file)
@@ -92,8 +92,8 @@ namespace System.ServiceModel.Channels.Http
                        AbortConnections (timeout);
                        // FIXME: this wait is sort of hack (because it should not be required), but without it some tests are blocked.
                        // This hack even had better be moved to base.CancelAsync().
-                       if (CurrentAsyncResult != null)
-                               CurrentAsyncResult.AsyncWaitHandle.WaitOne (TimeSpan.FromMilliseconds (300));
+//                     if (CurrentAsyncResult != null)
+//                             CurrentAsyncResult.AsyncWaitHandle.WaitOne (TimeSpan.FromMilliseconds (300));
                        return base.CancelAsync (timeout);
                }
 
@@ -104,12 +104,15 @@ namespace System.ServiceModel.Channels.Http
                }
 
                bool close_started;
+               object close_lock = new object ();
 
                protected override void OnClose (TimeSpan timeout)
                {
-                       if (close_started)
-                               return;
-                       close_started = true;
+                       lock (close_lock) {
+                               if (close_started)
+                                       return;
+                               close_started = true;
+                       }
                        DateTime start = DateTime.Now;
 
                        // FIXME: consider timeout
@@ -168,13 +171,14 @@ namespace System.ServiceModel.Channels.Http
 
                        Message msg = null;
 
-                       if (ctxi.Request.HttpMethod == "POST") {
+                       if (ctxi.Request.HttpMethod == "POST")
                                msg = CreatePostMessage (ctxi);
-                               if (msg == null)
-                                       return false;
-                       } else if (ctxi.Request.HttpMethod == "GET")
+                       else if (ctxi.Request.HttpMethod == "GET")
                                msg = Message.CreateMessage (MessageVersion.None, null); // HTTP GET-based request
 
+                       if (msg == null)
+                               return false;
+
                        if (msg.Headers.To == null)
                                msg.Headers.To = ctxi.Request.Url;
                        msg.Properties.Add ("Via", LocalAddress.Uri);