【问题标题】:socket.io + socket.io-redis adapter method calls timeoutsocket.io + socket.io-redis 适配器方法调用超时
【发布时间】:2021-03-13 22:03:15
【问题描述】:

我最近从 Socket.io 2.x 升级到 3.0.3 并将其与 socket-io-redis@6.0.1 一起使用。

按照原始迁移文档中的说明,我正在尝试获取所有打开套接字的列表:

const ids = await io.allSockets();

这会导致以下错误:

(node:20818) UnhandledPromiseRejectionWarning: Error: timeout reached while waiting for sockets response
    at Timeout._onTimeout (/var/app/node_modules/socket.io-redis/dist/index.js:286:28)
    at listOnTimeout (internal/timers.js:549:17)
    at processTimers (internal/timers.js:492:7)
(node:20818) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)

请注意,只有少数客户端连接到我的开发环境,因此它正在尝试处理太多可能导致超时的数据。

当我尝试在下面运行时遇到同样的错误:

const sockets = await io.of('/').adapter.sockets();
console.log(sockets); // a Set containing all the connected socket ids

const sockets = await io.of('/').adapter.sockets(new Set(['room1', 'room2']));
console.log(sockets); // a Set containing the socket ids in 'room1' or in 'room2'

// this method is also exposed by the Server instance
const sockets = io.in('room3').allSockets();
console.log(sockets); // a Set containing the socket ids in 'room3'

如果有人对导致问题的原因以及如何解决问题有任何想法,我们将不胜感激。

最好的

H

【问题讨论】:

标签: node.js express socket.io socket.io-redis


【解决方案1】:

在同一台服务器上运行另一个具有先前版本 (v2.x) 的 socket.io 服务器并连接到同一台 Redis 服务器,这就是导致问题的原因。

使用 v2.x 停止其他 socket.io 服务器并刷新 redis 数据库已解决此问题。

【讨论】:

    猜你喜欢
    • 2020-06-18
    • 2021-06-04
    • 2015-08-17
    • 1970-01-01
    • 1970-01-01
    • 2015-02-18
    • 2013-06-15
    • 1970-01-01
    • 2012-10-23
    相关资源
    最近更新 更多