GC Bug .net 2.0.50215

G

Guest

Async functionality prevents an object from garbage collection.

To reproduce:

Create a socket
establish connection
Create NetworkStream with Ownership Of a socket (or just work socket directly)
Call BeginReceive on stream or socket
dereference network stream
The conneciton will stay up until parent process is terminated.

What GC should be doing is releasing a handle of an underlying socket which
it does not.

pseudo code:

void init()
{
init socket
socket.connect()
init networkstream(owns the socket)
networkstream.beginread(async parameters)
}

void main()
{
for (int j = 0; j < 100; j++)
{
init();
}
GC.Collecti();
GC.WaitForPendingFinalizers();
break here (console read)
}

netstat will show 100 established connections that will never go away.
 
G

Guest

Looking at the pseudocode alone, I do not see deferencing of the Socket. The
read will finish, but that does not mean the socket has gone out of scope. If
this is the type of code you are looking at, the lack of GC cleaning the
objects is correct, as the Sockets are still active. Is there something more
that is missing from the pseudocode?


---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
G

Guest

Socket is declared within the funciton, the funciton exits, all external
references other then refernece from IOCP are gone, there is no way to get
the object out of IOCP pool without triggering send/rcvd action, if action
never comes up - hung connection. IMHO there should be a way to remove the
reference from IOCP or GC should do it by itself.
 
Top