SocketModeClient.disconnect() takes ~5 seconds to close on 3.0.1

クローズ
#2,752 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

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

2026年11月5日 から。

  • #2819 @WilliamBergamin による — オープン

評価

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

調査の方向性

Start at SocketModeClient.disconnect() and follow the WebSocket close handling and clientPingTimeout watchdog that produce the logged delay. Run the supplied slack-shutdown.mjs reproduction with the default and shortened ping timeout. Done means disconnect() resolves promptly after SIGINT without waiting for force termination, while preserving the expected close behavior.

索引モデルが issue の本文から書いたものです。

説明

auto-triage-skip bug pkg:socket-mode semver:patch
Package

@slack/socket-mode

SDK Version

3.0.1

Node.js Version

v26.10.0

Operating System

MacOS 26.5.1

Steps to Reproduce

Call repro: SLACK_APP_TOKEN=xapp-... node slack-shutdown.mjs

Reproduction script
package.json
{
  "name": "slack-repro",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "type": "module",
  "dependencies": {
    "@slack/socket-mode": "3.0.1"
  }
}
slack-shutdown.mjs
// Repro: what a Ctrl+C actually costs when disconnecting a Slack socket-mode
// client. Connects, waits for Ctrl+C, disconnects, and stamps every step.
//
//   SLACK_APP_TOKEN=xapp-… node slack-shutdown.mjs [--ping-timeout 1000]
//
// The client is built exactly like packages/channel-slack/src/connection.ts
// builds it (same options; --ping-timeout sets the SDK's clientPingTimeout,
// whose default is 5000 ms, to try other values). Install the version aivi
// pins next to this file: npm i @slack/[email protected]
//
// What the stamps say:
//   - the SDK's own lines (close frame sent/received, pong watchdog) arrive
//     through the routed logger, stamped with ms since start and since signal;
//   - `disconnect() resolved after Xms` is what aivi's teardown awaits;
//   - `event loop drained` is when the process is finally free to exit — the
//     gap after `resolved` is SDK handles (timers, sockets) holding a process
//     that already finished its work.
// A second Ctrl+C exits at once, like serve's.
import { SocketModeClient } from '@slack/socket-mode';

const appToken = process.env.SLACK_APP_TOKEN;
if (!appToken) {
  console.error('no SLACK_APP_TOKEN in the environment');
  process.exit(1);
}

const pingAt = process.argv.indexOf('--ping-timeout');
const pingTimeout = pingAt > 0 ? Number(process.argv[pingAt + 1]) : undefined;

const began = Date.now();
let signalAt = 0;
const at = () => `${String(Date.now() - began).padStart(6)}ms`;
const since = () => (signalAt ? ` (+${Date.now() - signalAt}ms from signal)` : '');
const line = level => (msg, ...rest) =>
  console.log(`${at()} ${level.padEnd(5)} ${msg}${rest.length ? ` ${rest.map(String).join(' ')}` : ''}`);

// Every SDK log line, routed here with a stamp: the close handshake, the pong
// watchdog, all of it, in order, with times.
const logger = {
  debug: line('debug'),
  info: line('info'),
  warn: line('WARN'),
  error: line('ERROR'),
  setLevel: () => {},
  getLevel: () => 'debug',
  setName: () => {},
};

const client = new SocketModeClient({
  appToken,
  clientOptions: { retryConfig: { retries: 0 } },
  logger,
  ...(Number.isFinite(pingTimeout) ? { clientPingTimeout: pingTimeout } : {}),
});

const pingLabel = Number.isFinite(pingTimeout) ? `clientPingTimeout=${pingTimeout}ms` : 'clientPingTimeout=default 5000ms';
console.log(`${at()} connect: start() (${pingLabel})`);
await client.start();
console.log(`${at()} connected — press Ctrl+C`);

process.on('beforeExit', () => console.log(`${at()} event loop drained — free to exit${since()}`));
process.on('exit', () => console.log(`${at()} process exit${since()}`));

let stopping = false;
process.once('SIGINT', async () => {
  if (stopping) {
    console.log(`${at()} second SIGINT — process.exit(1) now`);
    process.exit(1);
  }
  stopping = true;
  signalAt = Date.now();
  const readyStates = ['CONNECTING', 'OPEN', 'CLOSING', 'CLOSED'];
  const state = readyStates[client.websocket?.readyState ?? -1] ?? 'absent';
  console.log(`${at()} SIGINT — websocket is ${state}; calling disconnect() and awaiting it`);
  const started = Date.now();
  await client.disconnect();
  console.log(`${at()} disconnect() resolved after ${Date.now() - started}ms${since()}`);
  console.log(`${at()} our work is done; anything after this is the SDK's handles keeping the process alive`);
});
Reproduction output
Logs
     0ms debug The logLevel given to WebClient was ignored as you also gave logger
     1ms debug initialized
     1ms debug The Socket Mode client has successfully initialized
     1ms connect: start() (clientPingTimeout=default 5000ms)
     1ms debug Starting Socket Mode session ...
     1ms debug Going to retrieve a new WSS URL ...
     1ms debug apiCall('apps.connections.open') start
     2ms debug http request url: https://slack.com/api/apps.connections.open
     2ms debug http request body: {}
     2ms debug http request headers: {"User-Agent":"@slack:socket-mode/3.0.1 @slack:web-api/8.1.1 node/26.10.0 darwin/25.5.0","Accept":"application/json","Authorization":"[[REDACTED]]","Content-Type":"application/x-www-form-urlencoded"}
   221ms debug http response received
   223ms debug http request result: {"ok":true,"url":"wss://wss-primary.slack.com/link/?ticket=redacted&app_id=redacted","response_metadata":{"scopes":{"0":"connections:write"},"acceptedScopes":{"0":"connections:write"}}}
   223ms debug apiCall('apps.connections.open') end
   223ms debug Initiating new WebSocket connection.
   480ms debug WebSocket open event received (connection established)!
   480ms debug Started monitoring pings to and pongs from Slack.
   489ms debug Received a message on the WebSocket: {"type":"hello","num_connections":1,"debug_info":{"host":"applink-1","build_number":27,"approximate_connection_time":18060},"connection_info":{"app_id":"redacted"}}
   490ms connected — press Ctrl+C
^C  3890ms SIGINT — websocket is OPEN; calling disconnect() and awaiting it
  3891ms debug Manually disconnecting this Socket Mode client
  3891ms debug Sending close frame (status=1000).
 10482ms WARN  A pong wasn't received from the server before the timeout of 5000ms!
 10483ms debug Terminating WebSocket (close frame sent but no response, force-terminating).
 10483ms debug isActive(): websocket not instantiated!
 10483ms disconnect() resolved after 6593ms (+6593ms from signal)
 10483ms our work is done; anything after this is the SDK's handles keeping the process alive
 10483ms event loop drained — free to exit (+6593ms from signal)
 10483ms process exit (+6593ms from signal)
Expected Result

A disconnect.

Actual Result

A long delay, waiting for sdk's force quit. See log output in repro.

主要言語
TypeScript
スター
3.4k
フォーク
693
平均マージ
2日 5時間
マージ済み PR(30日)
37

環境構築

はじめの一歩

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

slackapi/node-slack-sdk のほかの issue

slackapi/node-slack-sdk の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

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

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