Reputation: 3784
I have a very weird bug that I know very little about here, so please bear with me.
I have a socket, connecting to a piece of hardware. I send synchronously, but receive asynchronously.
I send data via the following code:
_dicSockets[lclIPEndPoint].Send(lclBytesSent, lclBytesSent.Length, SocketFlags.None);
and receive via the following code:
protected virtual void receiveCallback(IAsyncResult ar)
{
PFDoReceiveDataArgs receiveData = (PFDoReceiveDataArgs)ar.AsyncState;
Socket lclSocket = receiveData.MySocket;
etc...
This scheme works fine when the hardware responds quickly, within 10seconds. However, crazy problems happen when the hardware takes longer (about 5 minutes) to respond. During this time, there is a thread which is in a while loop, checking whether the command received a response yet or not.
I know that the hardware is working and functional during this time. I send the command, and 5 minutes later, the response arrives. 4 out of 5 times, there is no problem, everything works as expected. Same command, same piece of hardware, same everything...
The 1 out of 5 times, there's a system-wide network crash where my internet connection is lost!
Since I have no idea what the problem could be, I'll wait for some ideas from you and paste more code as necessary.
Upvotes: 1
Views: 279
Reputation: 15569
When in doubt, sniff the network out. I had a problem years ago where a computer on the network was broadcasting malformed packets and would periodically take down our main Cisco switch. The mystery piece of hardware you're talking to might be broadcasting some horrible traffic the 1 out of 5 times.
I found the problem by sniffing the network while things were going wrong and was able to narrow down the problem.
Upvotes: 0
Reputation: 7203
Might not be related directly to the issue, but I would also dispose of the socket instance before the control leaves the receiveCallback method context.
Upvotes: 1