简体   繁体   English

Node.js 设置 setKeepAlive 不会通过 setTimeout 停止超时

[英]Node.js set setKeepAlive not stopping a timeout with setTimeout

I'm trying to figure out how Node.js's net class works with timeouts and keepalives.我试图弄清楚 Node.js 的网络类是如何处理超时和保活的。 I am setting them on the server side and watching to see what difference it makes setting these variables.我将它们设置在服务器端并观察设置这些变量有什么不同。 I notice that if I set the keepalive to the following:我注意到,如果我将 keepalive 设置为以下内容:

// Set keepalive
socket.setKeepAlive( true, 30000 );

It will absolutely in fact send keepalive packets which I observe with Wireshark.事实上,它绝对会发送我用 Wireshark 观察到的 keepalive 数据包。

使用 Wireshark 保持活力

However, even if I subscribe to the socket's timeout event, the socket will not timeout.但是,即使我订阅了套接字的超时事件,套接字也不会超时。 So I try setting the socket's timeout option.所以我尝试设置套接字的超时选项。

// Set timeout variables
socket.setTimeout( 60000 );

Even combined with the keepAlive option, the socket still times out after 60 seconds pretty much after its last real transmitted packet.即使与 keepAlive 选项结合使用,套接字仍然会在最后一个真正传输的数据包之后的 60 秒后超时。

连接超时

So my question is, what's the point of keepAlive if it doesn't really do anything to prevent socket timeouts?所以我的问题是,如果 keepAlive 没有真正做任何事情来防止套接字超时,那么它的意义何在?

socket.setTimeout() merely emits the timeout event when there has been no data received after whatever duration you specify. socket.setTimeout()仅在您指定的任何持续时间后没有收到数据时发出timeout事件。 The socket.setKeepAlive() is for sending keepalive probes as a means for detecting dead sockets. socket.setKeepAlive()用于发送 keepalive 探测作为检测死套接字的一种手段。

These two features are operating at two different "levels/layers."这两个功能在两个不同的“级别/层”上运行。 Keepalive probes are not considered "data," so that is why you're seeing the timeout event still. Keepalive 探测器不被视为“数据”,因此这就是您仍然看到timeout事件的原因。

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

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