[engine.io-client] close() called in an upgrade listener does not close the socket
维护者通常 2 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 20/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- node.js, typescript
- 领域
- backend, networking
调研方向
The issue points to packages/engine.io-client/lib/socket.ts and says a fix and test are already being submitted; linked pull request #5596 is open. Read that pull request and the upgrade handling around this.emitReserved("upgrade", transport) and this.upgrading = false to understand the change. The reported behavior is resolved when calling close() in an upgrade listener closes the socket immediately with reason forced close.
由索引模型根据 Issue 内容生成。
描述
Describe the bug
Calling socket.close() in a listener of the upgrade event does not close the socket. The socket stays in the closing state and the WebSocket connection stays open. Since the client no longer answers the pings in that state, the server closes the connection once pingTimeout expires, so the close event comes pingInterval + pingTimeout later (45 seconds with the default values), with the reason transport close instead of forced close.
The upgrade event is emitted before upgrading is set back to false, so close() waits for the upgrade to finish, that is, for an upgrade event that has already been emitted.
To Reproduce
Engine.IO server version: 6.6.11
Engine.IO client version: 6.6.8 (also reproduced on main)
Server and client
const { createServer } = require("node:http");
const { attach } = require("engine.io");
const { Socket } = require("engine.io-client");
const httpServer = createServer();
const engine = attach(httpServer, { pingInterval: 2000, pingTimeout: 1000 });
httpServer.listen(3000, () => {
const socket = new Socket("http://localhost:3000");
let closedAt;
socket.on("upgrade", () => {
closedAt = Date.now();
socket.close();
console.log("readyState right after close():", socket.readyState);
});
socket.on("close", (reason) => {
console.log(`"close" event ${Date.now() - closedAt} ms after close(), reason: ${reason}`);
engine.close();
httpServer.close();
});
});
Output:
readyState right after close(): closing
"close" event 3059 ms after close(), reason: transport close
Expected behavior
The socket is closed right away, as when close() is called at any other time:
"close" event 2 ms after close(), reason: forced close
readyState right after close(): closed
Platform:
- Device: desktop
- OS: Windows, Node.js 24.22.1
Additional context
In packages/engine.io-client/lib/socket.ts, this.upgrading = false comes after this.emitReserved("upgrade", transport). I'm opening a PR with a fix and a test.
AI-assisted: found and reproduced with an AI coding agent; the example above was run locally.
- 主要语言
- TypeScript
- 星标
- 63.2k
- 派生
- 10.2k
- 平均合并
- 6 天 4 小时
- 30 天内合并 PR
- 6
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
socketio/socket.io 的其他 Issue
-
[engine.io-client] The Node.js cookie jar lets Expires override Max-Age可能已有人在做 @Ayush701-code-zm 于 1 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 88/100
socketio/socket.io#5590 · 1 条评论 ·
维护者通常 2 天内回复
-
Raise Engine.IO minimum to 6.6.10 for published security fixes可能已有人在做 @harshit-exe-dev 于 29 天前认领。 未关闭
难度 1/5 1-3 小时 新手友好度 78/100
维护者通常 2 天内回复
-
Can't set response headers in Server.handleUpgrade可能已有人在做 @MsfPablo 于 90 天前认领。 未关闭question
难度 2/5 1-3 小时 新手友好度 72/100
socketio/socket.io#5497 · 2 条评论 ·
维护者通常 2 天内回复
-
WebTransport ignores query parameters in URL可能已有人在做 @cyphercodes 于 178 天前认领。 未关闭needs major release question
难度 2/5 1-3 小时 新手友好度 68/100
socketio/socket.io#5496 · 3 条评论 ·
维护者通常 2 天内回复
-
[engine.io-client] Node.js: cookies pile up in extraHeaders and are resent on every reconnection可能已有人在做 @adityajai119 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 20/100
维护者通常 2 天内回复
查看 socketio/socket.io 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 67/100
outline/outline#14529 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 86/100
g1331/phantom-circuit#93 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 68/100
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
compiler
难度 2/5 1-3 小时 新手友好度 74/100
HerringtonDarkholme/hd-lang#1699 ·
维护者通常 1 天内回复