The fix is similar to the one used in the TryRecycle() method: we defer connection closing until after we've left the lock. The original bug: https://bugzilla.xamarin.com/show_bug.cgi?id=27348
public void Close ()
{
+ List<WebConnection> connectionsToClose = null;
+
//TODO: what do we do with the queue? Empty it out and abort the requests?
//TODO: abort requests or wait for them to finish
lock (sPoint) {
var node = iter;
iter = iter.Next;
+ // Closing connections inside the lock leads to a deadlock.
+ if (connectionsToClose == null)
+ connectionsToClose = new List<WebConnection>();
+
+ connectionsToClose.Add (cnc);
connections.Remove (node);
+ }
+ }
+
+ if (connectionsToClose != null) {
+ foreach (var cnc in connectionsToClose) {
cnc.Close (false);
OnConnectionClosed ();
}