Merge pull request #463 from strawd/concurrent-requests
authorMiguel de Icaza <miguel@gnome.org>
Wed, 23 Sep 2015 18:37:01 +0000 (14:37 -0400)
committerMiguel de Icaza <miguel@gnome.org>
Wed, 23 Sep 2015 18:37:01 +0000 (14:37 -0400)
Handle multiple concurrent calls to BeginTryReceiveRequest

1  2 
mcs/class/System.ServiceModel/System.ServiceModel.Channels.Http/HttpReplyChannel.cs
mcs/class/System.ServiceModel/System.ServiceModel.Channels/ReplyChannelBase.cs

index d73b0866495cf0a32fe3ef8b2796ea619e8a36f2,9a66a32450063f6085f71f90d25a90a5f3b7e081..4e47ecf0035d8fda5470806c3f5ad8686b0c21f7
@@@ -126,36 -125,19 +127,36 @@@ namespace System.ServiceModel.Channel
                                        }
                                        try {
                                                return TryReceiveRequest (tout, out ctx);
 +                                      } catch (XmlException ex) {
 +                                              Console.WriteLine ("Xml Exception (Dropped Connection?):" + ex.Message);
 +                                              //on dropped connection, 
 +                                              //whatever you do don't crash
 +                                              //the whole app.  Ignore for now
 +                                      } catch (SocketException ex) {
 +                                              Console.WriteLine ("Socket Exception (Dropped Connection?):" + ex.Message);
 +                                              //on dropped connection, 
 +                                              //whatever you do don't crash
 +                                              //the whole app.  Ignore for now
 +                                      } catch (IOException ex) {
 +                                              Console.WriteLine ("I/O Exception (Dropped Connection?):" + ex.Message);
 +                                              //on dropped connection, 
 +                                              //whatever you do don't crash
 +                                              //the whole app.  Ignore for now
                                        } finally {
                                                lock (async_result_lock) {
-                                                       CurrentAsyncResult = null;
-                                                       CurrentAsyncThread = null;
+                                                       currentAsyncResults.Remove (result);
+                                                       currentAsyncThreads.Remove (Thread.CurrentThread);
                                                }
                                        }
 +                                      ctx = null;
 +                                      return false;
                                        });
                        RequestContext dummy;
-                       IAsyncResult result;
                        lock (async_result_lock) {
-                               result = CurrentAsyncResult = try_recv_delegate.BeginInvoke (timeout, out dummy, callback, state);
+                               result = try_recv_delegate.BeginInvoke (timeout, out dummy, callback, state);
+                               currentAsyncResults.Add (result);
                        }
-                       // Note that at this point CurrentAsyncResult can be null here if delegate has run to completion
+                       // Note that at this point result can be missing from currentAsyncResults here if delegate has run to completion
                        return result;
                }