Skip to content

fix: unsettled promise when request is aborted and compression is used and maxRedirects is set to 0#7149

Merged
jasonsaayman merged 3 commits intoaxios:v1.xfrom
ebeigarts:bugfix/handle-closed-socket
Apr 29, 2026
Merged

fix: unsettled promise when request is aborted and compression is used and maxRedirects is set to 0#7149
jasonsaayman merged 3 commits intoaxios:v1.xfrom
ebeigarts:bugfix/handle-closed-socket

Conversation

@ebeigarts
Copy link
Copy Markdown
Contributor

The axios request is left in an unsettled state (waits forever) when using compression and maxRedirects is set to 0 and the request gets aborted after some chunks are sent.

The problem is that the response abort event is not being emitted and the request state inside the responseStream.on('error') callback is destroyed: true, aborted: false.

I see that previoysly axios was checking req.aborted instead of req.destroyed inside the responseStream.on('error') callback, but since node deprecated the req.aborted, it was changed to req.destroyed in #4787.

We could change that back to req.aborted, but I think checking rejected would be a better option, so we can be sure that we are catching all the errors (in case there are some more weird cases).

Failing tests before:

  1) supports http with nodejs
       compression
         algorithms
           gzip decompression
             should throw an error if http server aborts and maxRedirects is 0:
     Error: Timeout of 30000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/ebeigarts/code/axios/test/unit/adapters/http.js)
      at listOnTimeout (node:internal/timers:608:17)
      at process.processTimers (node:internal/timers:543:7)

  2) supports http with nodejs
       compression
         algorithms
           GZIP decompression
             should throw an error if http server aborts and maxRedirects is 0:
     Error: Timeout of 30000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/ebeigarts/code/axios/test/unit/adapters/http.js)
      at listOnTimeout (node:internal/timers:608:17)
      at process.processTimers (node:internal/timers:543:7)

  3) supports http with nodejs
       compression
         algorithms
           compress decompression
             should throw an error if http server aborts and maxRedirects is 0:
     Error: Timeout of 30000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/ebeigarts/code/axios/test/unit/adapters/http.js)
      at listOnTimeout (node:internal/timers:608:17)
      at process.processTimers (node:internal/timers:543:7)

  4) supports http with nodejs
       compression
         algorithms
           deflate decompression
             should throw an error if http server aborts and maxRedirects is 0:
     Error: Timeout of 30000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/ebeigarts/code/axios/test/unit/adapters/http.js)
      at listOnTimeout (node:internal/timers:608:17)
      at process.processTimers (node:internal/timers:543:7)

  5) supports http with nodejs
       compression
         algorithms
           deflate-raw decompression
             should throw an error if http server aborts and maxRedirects is 0:
     Error: Timeout of 30000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/ebeigarts/code/axios/test/unit/adapters/http.js)
      at listOnTimeout (node:internal/timers:608:17)
      at process.processTimers (node:internal/timers:543:7)

  6) supports http with nodejs
       compression
         algorithms
           br decompression
             should throw an error if http server aborts and maxRedirects is 0:
     Error: Timeout of 30000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/ebeigarts/code/axios/test/unit/adapters/http.js)
      at listOnTimeout (node:internal/timers:608:17)
      at process.processTimers (node:internal/timers:543:7)

@nidhishgajjar

This comment was marked as spam.

1 similar comment
@nidhishgajjar

This comment was marked as spam.

@jasonsaayman jasonsaayman force-pushed the bugfix/handle-closed-socket branch from 899faae to 0018977 Compare April 28, 2026 15:35
@jasonsaayman jasonsaayman self-requested a review as a code owner April 28, 2026 15:35
@jasonsaayman jasonsaayman added priority::medium A medium priority commit::fix The PR is related to a bugfix labels Apr 28, 2026
@jasonsaayman jasonsaayman merged commit cd6737f into axios:v1.x Apr 29, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commit::fix The PR is related to a bugfix priority::medium A medium priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants