Skip to content

Conversation

@ebeigarts
Copy link

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)

…d and maxRedirects is set to 0

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 axios#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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr::fix PR that fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants