简体   繁体   English

一台计算机上的C#TCP应用程序死锁而另一台计算机上永不死锁

[英]C# TCP Application deadlocks on one computer and never deadlocks on another

I'm not sure how to approach this. 我不确定该如何处理。 I am hesitant about showing my code because it's a university assignment. 我不愿意显示我的代码,因为这是大学的任务。 I need some place to start. 我需要一些起点。

I'm making a TCP card game with four players and a server. 我正在制作一个有四个玩家和一个服务器的TCP卡游戏。 Every 100ms, a player asks for an update from the server using a background worker. 每隔100毫秒,播放器就会使用后台工作程序从服务器请求更新。 The server accepts a client connection and reads in a Enumeration value (sent as an Int32) that tells it the action it wants server to send it (update, card, player, etc) and a value that is read in based on the Enumeration value (Recieving an Update Enumeration means it needs to read in a Int32 next). 服务器接受客户端连接,并读取一个Enumeration值(以Int32形式发送),该值指示服务器希望服务器发送它的动作(更新,卡,播放器等),以及基于Enumeration值读取的值(接收更新枚举意味着接下来需要读取Int32)。 The server sends back a response based on the Enumeration read in. 服务器基于读入的Enumeration发回响应。

Here's where the problem occurs. 这是发生问题的地方。 I have a custom built computer (2500K processor, Win8 x64) and when I execute the program on it, it will loop forever, accepting client requests and sending the appropriate response back. 我有一台定制的计算机(2500K处理器,Win8 x64),当我在其上执行程序时,它将永远循环,接受客户端请求并将适当的响应发送回去。 Exactly as expected! 完全符合预期! However, on my laptop (Levono YogaPad, Win8 x64) the back and forth exchange lasts for around 30-50 requests and then deadlocks. 但是,在我的笔记本电脑(Levono YogaPad,Win8 x64)上,来回交换持续约30-50个请求,然后出现死锁。 It's always at the same spot. 它总是在同一地点。 The server has read in the Enumeration and is awaiting for the second value. 服务器已读入枚举,正在等待第二个值。 The client is past the part of sending the enum and value and is waiting for the results. 客户端已超出发送枚举和值的部分,正在等待结果。 It is always stable on my desktop and always deadlocks on my laptop. 它在我的台式机上始终稳定,在笔记本电脑上始终死锁。 I even slow the program down to update every second and it still deadlocks. 我什至放慢了程序的速度以每秒更新一次,但它仍然死锁。 I'm not sure what to do. 我不确定该怎么办。

I've built the program on each computer. 我已经在每台计算机上构建了该程序。 I've built the program on my desktop and ran it on my laptop and it still deadlocks. 我已经在台式机上构建了该程序,并在笔记本电脑上运行了该程序,但仍然陷入僵局。 Does anyone have any suggestions? 有没有人有什么建议?

Many thanks! 非常感谢!

You are lucky that the code hangs on one machine before you send the assignment in and it hangs on your teachers machine. 您很幸运,在您发送作业之前,该代码已挂在一台计算机上,并且已挂在您的教师计算机上。 You are also lucky that the problem is reproducible, so better find out where exactly it hangs. 您也很幸运,该问题是可重现的,因此最好找出问题的根源。 Without having access to the code I have the following wild guesses: 在无法访问代码的情况下,我有以下疯狂的猜测:

  • you forgot to do proper error handling in all places and now it busy loops because of an unexpected error 您忘记了在所有地方进行正确的错误处理,现在由于意外错误而导致繁忙的循环
  • it hangs inside a read where you try to read N bytes but the peer sends only K<N bytes 它挂在您尝试读取N个字节的读取内部,但对等方仅发送K<N个字节

These are wild guesses, but without having access to even the basic structure of your program you cannot probably expect anything more. 这些都是大胆的猜测,但是即使没有访问程序的基本结构,也可能无法期望更多。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM