Socket closed unexpectedly after 5 seconds

未关闭
#2,855 4 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

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

调研方向

从 packages/client/lib/client/socket.ts 开始,重点查看 #createSocket,并使用报告中的 Redis 复制和客户端配置复现五秒后断开连接的问题。跟踪初始连接后的超时处理,并确定保持 socket 活跃的受支持行为;当原因以及预期的配置或代码变更已确定,并由回归检查覆盖时,即视为完成。

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

描述

Bug
Description

I'm running redis with replication, with the simple client configuration createClient({ url }). After the initial connection is successfully established, the socket is closed after 5 seconds. I guess this is because the socket connectTimeout is by default 5s, and in packages/client/lib/client/socket.ts, it'll close it based on the property.

async #createSocket(): Promise<net.Socket | tls.TLSSocket> {
    const socket = this.#socketFactory.create();

    let onTimeout;
    if (this.#connectTimeout !== undefined) {
      onTimeout = () => socket.destroy(new ConnectionTimeoutError());
      socket.once('timeout', onTimeout);
      socket.setTimeout(this.#connectTimeout);
    }
    ....
    return socket;
  }

I've already taken a look into other related issues, and I tried setting pingInterval and setting socket connectTimeout to 0, and as expected, the socket is closed regardless. What is the recommended way to keep the socket connection alive?

INFO:
Redis is deployed via Helm (bitnami 20.1.4) into kubernetes cluster, with one master node and 3 replicas.

Node.js Version

20.14.0

Redis Server Version

7.4.0

Node Redis Version

4.7.0

Platform

Linux

Logs

No response

主要语言
TypeScript
星标
17.6k
派生
2k
平均合并
1 天 22 小时
30 天内合并 PR
62

环境准备

从这里开始

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

redis/node-redis 的其他 Issue

查看 redis/node-redis 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

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