Moved WebConnectionGroup.Close() call out of the ServicePoint lock
authorHellBrick <hellbrick@webkontrol.ru>
Mon, 30 Mar 2015 09:45:27 +0000 (12:45 +0300)
committerHellBrick <hellbrick@webkontrol.ru>
Mon, 30 Mar 2015 09:45:27 +0000 (12:45 +0300)
WebConnectionGroup.Close() calls WebConnection.Close(), which takes connection lock and then takes the service point lock. Calling WebConnectionGroup.Close() leads to taking the service point lock *before* the connection lock, which leads to a deadlock.

mcs/class/System/System.Net/ServicePoint.cs

index 2a2c1cb048fa6aa63336ee442c7902bb971fa39c..bb47c65c48faa262a6dedeeafc554390e796d4cd 100644 (file)
@@ -401,15 +401,21 @@ namespace System.Net
                }
                public bool CloseConnectionGroup (string connectionGroupName)
                {
+                       WebConnectionGroup cncGroup = null;
+
                        lock (this) {
-                               WebConnectionGroup cncGroup = GetConnectionGroup (connectionGroupName);
+                               cncGroup = GetConnectionGroup (connectionGroupName);
                                if (cncGroup != null) {
-                                       cncGroup.Close ();
                                        RemoveConnectionGroup (cncGroup);
-                                       return true;
                                }
                        }
 
+                       // WebConnectionGroup.Close() must *not* be called inside the lock
+                       if (cncGroup != null) {
+                               cncGroup.Close ();
+                               return true;
+                       }
+
                        return false;
                }