Skip to content

Commit

Permalink
Handle special case when disposing a socket.
Browse files Browse the repository at this point in the history
	When disposing a socket that has more than one asynchronous read/write
	pending, one of the callbacks could call DisposeAllOnClose() while
	another one is waiting on the lock. Once the lock is acquired,
	queue.Count will be 0 and Dequeue would fail.
	This if fixed now.

	Fixes bug #645675.
  • Loading branch information
gonzalop committed Oct 12, 2010
1 parent 9f62005 commit 936c28a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion mcs/class/System/System.Net.Sockets/Socket_2_1.cs
Expand Up @@ -236,7 +236,11 @@ public void Complete ()
SocketAsyncCall sac = null;
SocketAsyncResult req = null;
lock (queue) {
queue.Dequeue (); // remove ourselves
// queue.Count will only be 0 if the socket is closed while receive/send
// operation(s) are pending and at least one call to this method is
// waiting on the lock while another one calls CompleteAllOnDispose()
if (queue.Count > 0)
queue.Dequeue (); // remove ourselves
if (queue.Count > 0) {
worker = (Worker) queue.Peek ();
if (!Sock.disposed) {
Expand Down

0 comments on commit 936c28a

Please sign in to comment.