Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#2,752 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
58/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
node.js, typescript
Ambito
api, networking

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

untriaged
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.

Lingua principale
TypeScript
Stelle
3.4k
Fork
688
Merge medio
1g 49m
PR unite (30g)
15

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di slackapi/node-slack-sdk

Tutte le issue di slackapi/node-slack-sdk

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.