[engine.io-client] close() called in an upgrade listener does not close the socket

Đang mở
#5,595 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@adityajai119 đang làm issue này rồi.

Từ ngày 11/11/2026.

  • #5596 của @adityajai119 — đang mở

Đá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

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của socketio/socket.io

Tất cả issue của socketio/socket.io

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.