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

オープン
#5,595 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

@adityajai119 がすでに取り組んでいます。

2026年11月11日 から。

  • #5596 @adityajai119 による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
20/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
node.js, typescript

調査の方向性

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時間
マージ済み PR(30日)
6

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

socketio/socket.io のほかの issue

socketio/socket.io の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。