简体   繁体   English

TCP 通讯器在一段时间后停止工作

[英]TCP communicator stops working after some time

We are developing a vehicle tracking system.我们正在开发车辆跟踪系统。 Like every VTS, we have GPS devices fitted into the vehicles and those devices send the vehicle location details to the server.与每个 VTS 一样,我们在车辆中安装了 GPS 设备,这些设备将车辆位置详细信息发送到服务器。 We have developed a TCP communicator which keeps running and checking if there is any connect-request at a specific port.我们开发了一个 TCP 通信器,它会持续运行并检查特定端口是否有任何连接请求。 If there is any, it creates a thread for that device and that thread saves all the device location details.如果有,它会为该设备创建一个线程,并且该线程会保存所有设备位置详细信息。 The TCP communicator runs as expected for 12 to 16 hours. TCP 通信器按预期运行 12 到 16 小时。 But after 12-16 hours, it stops responding.但在 12-16 小时后,它停止响应。 There is not error or exception in logs.日志中没有错误或异常。 Also even the pid file is also present, so process has not been killed.甚至 pid 文件也存在,所以进程没有被杀死。 What can be the possible problem and how should I go about debugging the issue?可能是什么问题,我应该如何调试问题?

Thanks in advance提前致谢

I believe that you do not close connections, streams or something like this.我相信您不会关闭连接、流或类似的东西。 You mentioned PID file, so I guess you are running on Linux.您提到了 PID 文件,所以我猜您正在 Linux 上运行。 Linux creates handler every time you get network connection or open file or create process.每次获得网络连接或打开文件或创建进程时,Linux 都会创建处理程序。 Number of handlers is limited.处理程序的数量是有限的。 Unfortunately I do not remember the shell command by heart but I remember that command that can show you all handlers exists.不幸的是,我不记得 shell 命令,但我记得可以显示所有处理程序的命令存在。

So, I'd recommend you to perform the following.因此,我建议您执行以下操作。 I believe that your system updates the details periodically.我相信您的系统会定期更新详细信息。 Let's say every minute.让我们说每一分钟。 So make the system to do this every second (or 100 times per second if you want).因此,让系统每秒执行一次(或者如果需要,每秒执行 100 次)。 I believe it will stuck faster.我相信它会卡得更快。 Now decrease the period and see that it will continue working after 16 hours you mentioned.现在减少时间,看看它会在你提到的 16 小时后继续工作。 If this will be the behavior my assumption about the handlers is correct.如果这将是我对处理程序的假设是正确的行为。 So, try to review your code and see that every time you open input/output stream you close it properly into finally .因此,请尝试查看您的代码,并查看每次打开输入/输出 stream 时都会正确地将其关闭到finally中。 Probably add logging after creating and closing streams.可能在创建和关闭流后添加日志记录。

Good luck!祝你好运!

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

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