[Http]: Only recycle ServicePoints from the idle timer (fixes #19823).
authorMartin Baulig <martin.baulig@xamarin.com>
Tue, 10 Jun 2014 17:13:10 +0000 (19:13 +0200)
committerMartin Baulig <martin.baulig@xamarin.com>
Tue, 10 Jun 2014 17:21:32 +0000 (19:21 +0200)
Thanks a lot for Martin Potter to find and report the race condition
which was causing the problem.

ServicePointManager.RecycleServicePoints() was a left-over from the
old times when we didn't have an idle-timer based approach.

mcs/class/System/System.Net/ServicePointManager.cs

index 26578856fae1beb3bc182f186d22811ce8103be5..66cdc7296feca5dbcbccaa586ad7deceeaf7d01f 100644 (file)
@@ -264,7 +264,6 @@ namespace System.Net
                                        throw new ArgumentException ("value");                          
 
                                maxServicePoints = value;
-                               RecycleServicePoints ();
                        }
                }
 
@@ -329,9 +328,6 @@ namespace System.Net
                        if (address == null)
                                throw new ArgumentNullException ("address");
 
-                       if ((servicePoints.Count % 4) == 0)
-                               RecycleServicePoints ();
-
                        var origAddress = new Uri (address.Scheme + "://" + address.Authority);
                        
                        bool usesProxy = false;
@@ -378,41 +374,6 @@ namespace System.Net
                        return sp;
                }
                
-               // Internal Methods
-
-               static void RecycleServicePoints ()
-               {
-                       lock (servicePoints) {
-                               var toRemove = new ArrayList ();
-                               var idleList = new SortedDictionary<DateTime, ServicePoint> ();
-                               IDictionaryEnumerator e = servicePoints.GetEnumerator ();
-                               while (e.MoveNext ()) {
-                                       ServicePoint sp = (ServicePoint) e.Value;
-                                       DateTime idleSince;
-                                       if (sp.CheckAvailableForRecycling (out idleSince)) {
-                                               toRemove.Add (e.Key);
-                                               continue;
-                                       }
-
-                                       while (idleList.ContainsKey (idleSince))
-                                               idleSince = idleSince.AddMilliseconds (1);
-                                       idleList.Add (idleSince, sp);
-                               }
-                               
-                               for (int i = 0; i < toRemove.Count; i++) 
-                                       servicePoints.Remove (toRemove [i]);
-
-                               if (maxServicePoints == 0 || servicePoints.Count <= maxServicePoints)
-                                       return;
-
-                               // get rid of the ones with the longest idle time
-                               foreach (var sp in idleList.Values) {
-                                       if (servicePoints.Count <= maxServicePoints)
-                                               break;
-                                       servicePoints.Remove (sp);
-                               }
-                       }
-               }
 #if SECURITY_DEP
                internal class ChainValidationHelper {
                        object sender;