简体   繁体   English

C#异步接收会导致系统范围的网络崩溃!

[英]C# asynchronous receive causes system-wide network crash!

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. 当硬件在10秒内快速响应时,此方案可以正常工作。 However, crazy problems happen when the hardware takes longer (about 5 minutes) to respond. 但是,当硬件花费更长的时间(大约5分钟)来响应时,就会发生疯狂的问题。 During this time, there is a thread which is in a while loop, checking whether the command received a response yet or not. 在这段时间内,有一个线程处于while循环中,以检查命令是否已收到响应。

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. 5次中有4次没有问题,一切正常。 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! 5次中有1次发生系统范围的网络崩溃,我的互联网连接丢失了!

Since I have no idea what the problem could be, I'll wait for some ideas from you and paste more code as necessary. 由于我不知道问题可能出在哪里,因此我将等待您的想法,并根据需要粘贴更多代码。

可能与问题不直接相关,但是我还将在控件离开receiveCallback方法上下文之前处理套接字实例。

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. 几年前,我遇到了一个问题,网络上的一台计算机正在广播格式错误的数据包,并且会定期关闭我们的主要Cisco交换机。 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. 我通过在出现问题的情况下嗅探网络来发现问题,并能够缩小问题的范围。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 设计Qn RE:系统范围的计时器(C#)。 什么计时器在哪一层? - Design Qn RE: System-wide timer (C#). What timer in what layer? 如何在C#中通过Windows资源管理器有效监视系统范围的“文件名更改事件” - How to monitor system-wide “file name change event” by windows explorer effectively in c# 从C#应用程序在整个系统的空闲隐藏鼠标上进行动态显示 - On Idle Hide Mouse System-Wide, Show on Movement, from a C# Application C#异步接收 - C# Asynchronous Receive 与“系统级”媒体播放器互动 - Interact with “system-wide” media player 取消处理(取消注册)系统范围的“HotKey” - Unhandling (unregistering) a system-wide 'HotKey' 是.net系统范围内的垃圾收集器还是应用程序范围内的垃圾收集器? - Is the garbage collector in .net system-wide or application-wide? 使用异步方法在C#中接收请求 - Receive a request in c# with asynchronous methods .NET系统范围内的EventWaitHandle名称允许的字符 - .NET system-wide EventWaitHandle name allowed characters 从DB处理队列时,系统范围互斥的替代方案? - alternatives to system-wide mutex when processing queue from DB?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM