Subject: Race condition in SynchronousConnect/EndConnect
In investigating issues with the communications in our product's use of the MatriX code I've noticed that there's a race situation in the code (at least in the V1.4.4.0 of the source code that we have) between SynchronousConnect & EndConnect.
SynchronousConnect has a 5 second timeout, and should that expire (which it does if there's no connection), it closes the socket and sets the socket member variable to null.
EndConnect will then try to use that socket object, resulting in an ArgumentNullExeception - albeit that it is handled in an exception handler and doesn't seem to cause any obvious subsequent issues.
Why does SynchronousConnect have a timeout value when EndConnect always gets called (eventually)?
I note that the MS documentation for Socket.BeginConnect http://msdn.microsoft.com/en-us/library/tad07yt6.aspx says "At the very minimum, you must pass the Socket to BeginConnect through the state parameter." - which isn't done in the version of the MatriX code we have. Presumably the intention is that the socket object can be obtained in EndConnect via ar.AsyncState?
Also, since ClientSocket has a Socket member (which is IDisposable), shouldn't ClientSocket also be IDisposable?
Have there been any changes to this code in the latest version to resolve comms issues?
SynchronousConnect has a 5 second timeout, and should that expire (which it does if there's no connection), it closes the socket and sets the socket member variable to null.
EndConnect will then try to use that socket object, resulting in an ArgumentNullExeception - albeit that it is handled in an exception handler and doesn't seem to cause any obvious subsequent issues.
Why does SynchronousConnect have a timeout value when EndConnect always gets called (eventually)?
I note that the MS documentation for Socket.BeginConnect http://msdn.microsoft.com/en-us/library/tad07yt6.aspx says "At the very minimum, you must pass the Socket to BeginConnect through the state parameter." - which isn't done in the version of the MatriX code we have. Presumably the intention is that the socket object can be obtained in EndConnect via ar.AsyncState?
Also, since ClientSocket has a Socket member (which is IDisposable), shouldn't ClientSocket also be IDisposable?
Have there been any changes to this code in the latest version to resolve comms issues?