简体   繁体   English

Socket.io延迟解雇“断开连接”事件?

[英]Socket.io delay in firing the “disconnect” event?

I have a socket.io client connected to a node.js server. 我有一个socket.io客户端连接到node.js服务器。 If I kill node.js at the command line, the client immediately freezes (ie, communication stops), but there is a ~20 second delay before the "disconnect" event is fired. 如果我在命令行中杀死node.js,客户端会立即冻结(即通信停止),但在“disconnect”事件被触发之前有大约20秒的延迟。 Is this behavior by design? 这种行为是设计的吗? Is there a configuration option to reduce the delay in firing the disconnect event? 是否有配置选项来减少触发断开连接事件的延迟?

It appears that this behavior changed in a relatively recent (last 6 months) update of socket.io. 看来这种行为在socket.io的最新(最近6个月)更新中发生了变化。 Before the reconnect functionality was built in to socket.io itself, I implemented my own reconnect logic using a "disconnect" event handler and at that time the "disconnect" event fired almost instantly when server communication halted. 在重新连接功能内置到socket.io本身之前,我使用“disconnect”事件处理程序实现了我自己的重新连接逻辑,并且当服务器通信暂停时,“disconnect”事件几乎立即触发。

Yes. 是。 close timeout . 关闭超时

I think this is likely a design pattern. 我认为这可能是一种设计模式。 The client may be presuming the server is 'temporarily' unreachable (network trafic etc) and essentially will keep trying to reach it... until the client timeout kicks in. 客户端可能假设服务器“暂时”无法访问(网络流量等)并且基本上将继续尝试到达它...直到客户端超时开始。

I send a disconnect (socket.disconnect()) to the server directly from the client, and I don't get this issue. 我直接从客户端向服务器发送断开连接(socket.disconnect()),我没有遇到此问题。

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

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