[engine.io-client] close() called in an upgrade listener does not close the socket
Maintainer thường phản hồi trong vòng 2 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 20/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- node.js, typescript
- Lĩnh vực
- backend, networking
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- TypeScript
- Star
- 63.2k
- Fork
- 10.2k
- Merge trung bình
- 6 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 6
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của socketio/socket.io
-
[engine.io-client] The Node.js cookie jar lets Expires override Max-AgeCó thể đã có người làm @Ayush701-code-zm đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
socketio/socket.io#5590 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Raise Engine.IO minimum to 6.6.10 for published security fixesCó thể đã có người làm @harshit-exe-dev đã nhận 29 ngày trước. Đang mở
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Can't set response headers in Server.handleUpgradeCó thể đã có người làm @MsfPablo đã nhận 90 ngày trước. Đang mởquestion
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
socketio/socket.io#5497 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
WebTransport ignores query parameters in URLCó thể đã có người làm @cyphercodes đã nhận 178 ngày trước. Đang mởneeds major release question
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
socketio/socket.io#5496 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[engine.io-client] Node.js: cookies pile up in extraHeaders and are resent on every reconnectionCó thể đã có người làm @adityajai119 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 20/100
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của socketio/socket.io
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
outline/outline#14529 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 86/100
g1331/phantom-circuit#93 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
compiler
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
HerringtonDarkholme/hd-lang#1699 ·
Maintainer thường phản hồi trong vòng 1 ngày