Socket.IO stops working randomly until page refresh

未关闭
#5,299 9 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞
技术栈
node.js, redis, typescript

调研方向

先从提供的 TypeScript 前端连接配置和后端启动配置入手,然后在观察 namespace、重连和 Redis 行为的同时复现随机断开连接。确定一个可复现的原因并记录范围明确的修复方案或诊断结果,即表示完成;该 issue 未指定任何 repository 文件或测试。

由索引模型根据 Issue 内容生成。

描述

needs investigation

Hi, I'm using Socket.IO in a Node.js project, and sometimes the socket connection just stops working. The only way to get it working again is by refreshing the browser page.

I'm using namespaces to separate tenants, and Redis to manage socket IDs. Here is my frontend and backend configuration:

Frontend (Client-side):

export function connectSocketToNamespace(namespace: string): void {
    socket = io(`${import.meta.env.VITE_SERVER_URL}/${namespace}`, {
        auth: {
            token: getAuthToken()
        },
        query: {
            sessionKey: getSession()
        },
        transports: ["websocket"],
        upgrade: false,
        reconnection: true,
        reconnectionAttempts: Infinity,
        reconnectionDelay: 2000,
        reconnectionDelayMax: 10000,
        randomizationFactor: 0.5,
    });
}

Backend (Server-side - AdonisJS):

public boot() {
    if (!this.booted) {
        this.io = new Server(AdonisServer.instance!, {
            maxHttpBufferSize: maxUploadFileSize(),
            pingInterval: 10000,
            pingTimeout: 25000,
            cors: {
                origin: Env.get('CLIENT_URL')
            }
        });

        this.booted = true;

        this.configureNamespaces();
        this.clearOldSockets();
    }
}

There are no errors in the console or server logs, and this issue happens randomly.

Has anyone experienced something similar? Could this be related to the Redis adapter or the namespace handling? Any suggestions on debugging or fixing this issue?

Thanks in advance!

主要语言
TypeScript
星标
63.2k
派生
10.2k
平均合并
6 天 4 小时
30 天内合并 PR
6

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

socketio/socket.io 的其他 Issue

查看 socketio/socket.io 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。