Skip to content

web-api v8 no longer retries interrupted response bodies #2738

Open

Description

@pkaminski

Package

@slack/web-api

SDK Version

8.1.1

Node.js Version

24.21.0

Operating System

Microsoft Windows [Version 10.0.26200.9445]

Steps to Reproduce

Run this with each SDK version. The server drops the first response after sending HTTP 200 headers and part of the body, then succeeds on retry.

const http = require('node:http');
const { WebClient } = require('@slack/web-api');

let requests = 0;
const server = http.createServer((req, res) => {
  req.resume();
  if (++requests === 1) {
    res.writeHead(200, { 'Content-Type': 'application/json', 'Content-Length': '100' });
    res.write('{"ok":');
    setTimeout(() => res.destroy(), 50);
  } else {
    res.end('{"ok":true}');
  }
});

server.listen(0, '127.0.0.1', async () => {
  const client = new WebClient('unused', {
    slackApiUrl: `http://127.0.0.1:${server.address().port}/`,
    retryConfig: { retries: 1, minTimeout: 1, maxTimeout: 1 },
  });
  try {
    console.log(await client.auth.test());
  } catch (error) {
    console.log(error.name, error.message, error.code);
  } finally {
    console.log({ requests });
    server.closeAllConnections();
    server.close();
  }
});

Expected Result

The call should retry once and return { ok: true, response_metadata: {} }, with { requests: 2 }, as 7.19.0 does.

The automatic retries docs say "The client will retry a failed API method call up to 10 times"; this repro sets retries: 1. The error-handling docs also say SDK errors have a code property.

Actual Result

With 8.1.1, the repro prints:

TypeError terminated undefined
{ requests: 1 }

auth.test() rejects after the first request without retrying. The error is a raw TypeError, and error.code is undefined.

makeRequest() retries fetch(), but buildResult() reads response.text() outside that retry loop. A disconnect while reading the body therefore skips both retrying and error wrapping.

Activity

  1. WilliamBergamin commented on Sep 10, 2026

    @WilliamBergamin
    Contributor

    Hi @pkaminski thanks for the exceptionally clear repro and diagnosis 🙏

    I was able to confirm this this locally

    Reproduced locally with your script:

    • @slack/web-api@8.1.1 → TypeError terminated (error.code is undefined), { requests: 1 } (no retry)
    • @slack/web-api@7.19.0 → { ok: true, response_metadata: {} }, { requests: 2 } (retries and succeeds)

    The regression comes from the v7→v8 move from axios to fetch. makeRequest() wraps only the fetch() call in pRetry and returns the Response before its body is read; the body is then read in buildResult() via response.text(), which is both outside the retry loop and outside the try/catch that wraps failures into a coded WebAPIRequestError. So a disconnect while reading a 200 body neither retries nor gets a code (hence error.code === undefined). Under axios the body was materialized inside the retried request, so the same interruption was retried and wrapped.

    We'll treat this as a bug on our side. Until it's patched, two options:

    • Pass a custom fetch that fully buffers the body before returning, so the interruption happens inside the retried/wrapped path (I verified this flips your repro to { requests: 2 } / { ok: true } on 8.1.1):
    const bufferingFetch = async (url, init) => {
      const res = await fetch(url, init);
      const body = await res.arrayBuffer(); // interruption throws here, inside makeRequest's retry + error-wrapping
      return new Response(body, { status: res.status, statusText: res.statusText, headers: res.headers });
    };
    const client = new WebClient(token, { fetch: bufferingFetch });
  2. added
    bugM-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented
    pkg:web-apiapplies to `@slack/web-api`
    and removed on Sep 10, 2026
  3. added a commit that references this issue on Sep 10, 2026
    e134198
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    auto-triage-skipbugM-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documentedpkg:web-apiapplies to `@slack/web-api`semver:patch

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions