Skip to content

Commit

Permalink
Fixed deadlock in WebConnectionGroup.Close()
Browse files Browse the repository at this point in the history
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
  • Loading branch information
HellBrick committed Mar 26, 2015
1 parent 6808e6a commit 893baca
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions mcs/class/System/System.Net/WebConnectionGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ void OnConnectionClosed ()

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) {
Expand All @@ -76,7 +78,17 @@ public void Close ()
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 ();
}
Expand Down

0 comments on commit 893baca

Please sign in to comment.