流星连接超时调整

Rob*_*ijk 4 javascript connection connection-timeout meteor

有没有办法更改连接断开的超时 Meteor 句柄?

用例:我们有一个服务器,连接到多个客户端。一旦客户端上的连接断开,例如通过拔出以太网电缆,我们希望反映客户端已脱机。但是,由于连接超时似乎是大约 30 秒,因此服务器需要大约这么长时间才能注意到断开连接并将客户端置于离线状态。

我们尝试过的事情: - 更改客户端的心跳率,这对客户端有效,因为它们会更快地断开连接。不过,这不会影响服务器上的行为,因为服务器仍会等待大约 30 秒来调用连接断开。

  • 实现我们自己的心跳方法,它有 3 秒的间隔,以检测连接中断。然而,这会导致大量额外的代码用于我期望可配置的东西。

我一直无法在文档中找到有关减少连接超时的任何内容。

Mas*_*rAM 6

Meteor 使用SockJS作为它的 websocket 服务器。

由于性能问题(如果 cpu 忙得太久,用户会断开连接),Meteor 早期的断开延迟设置为 60 秒,并且无法配置。

// The default disconnect_delay is 5 seconds, but if the server ends up CPU
// bound for that much time, SockJS might not notice that the user has
// reconnected because the timer (of disconnect_delay ms) can fire before
// SockJS processes the new connection. Eventually we'll fix this by not
// combining CPU-heavy processing with SockJS termination (eg a proxy which
// converts to Unix sockets) but for now, raise the delay.
disconnect_delay: 60 * 1000,
Run Code Online (Sandbox Code Playgroud)

来源:Meteor ddp-server 包

ddp-server如果您希望快速更改,您很可能需要 fork包并覆盖它。