Bug found in System.Net.Sockets.Socket class

  • Thread starter Thread starter Oren Shomron
  • Start date Start date
O

Oren Shomron

Hello,

I came across an annoying bug in the Socket class.
Apparently its GetHashCode() implementation returns
its Handle property value.

Since calling Close() sets the Handle to -1, GetHashCode()
returns -1 as well.

This has the effect of socket objects *changing identity* on me.

See the following example:

// Add a socket as the key in my hashtable:
Hashtable hash = new Hashtable();
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp);
hash.Add(sock, new Integer(2));

// Close the socket
sock.Close();

// Fails! hash.Count is still 1!!!!!
hash.Remove(sock);

--------------------------------------------
This is obviously a bug.
Does anyone know how to get this behavior changed for the next
Framework release?

Thanks,
- Oren Shomron
 
This is obviously a bug.

Yes, I do believe it is.
Does anyone know how to get this behavior changed for the next
Framework release?

By the looks of things, this bug will not occur in the next version of the
framework(based on the existing public build). Socket apparently no longer
overrides GetHashCode and therefore will simply use the object.GetHashCode
implementation.
I suspect it was probably fixed due to chnages in the way object.GetHashCode
works, but it looks like it is fixed now.

Incase you run across another bug that isn't fixed: There is no easy way to
report bugs in the 1.1 framework that I can tell of. Posting it here may be
your best be, someone from Microsoft or an MVP may see it and be able to
escalate it. But you can report bugs in the 2.0 to the product feedback
center at http://lab.msdn.microsoft.com/productfeedback/default.aspx

You will need to get the public 2.0 runtime and run a test to see if it
occurs(this one probably won't, but I urge you to test it anyway). If the
bug still appears to be there, lodge a report on the feedback center and
reply with the URL and a test and I'll validate it.
 
Back
Top