Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node timeout for partial response results in AxiosError: maxContentLength size of -1 exceeded #5238

Open
WestonThayer opened this issue Nov 8, 2022 · 5 comments

Comments

@WestonThayer
Copy link

WestonThayer commented Nov 8, 2022

Describe the bug

The timeout option causes an unexpected type of Error to be thrown in Node when the server sends the first response chunk within the timeout, but then hangs.

To Reproduce

  1. Load https://codesandbox.io/s/jovial-farrell-z2qvkd?file=/src/index.js

Inspect console output.

Code snippet

const axios = require("axios");
const http = require("http");

const server = http.createServer((req, res) => {
  res.write("partial response");
  setTimeout(() => res.end(), 2000);
});
server.listen(3000);

axios
  .get("http://localhost:3000", { timeout: 1000 })
  .then(() => console.log("got response"))
  .catch((error) => console.log(error));

Expected behavior

AxiosError: timeout of 1000ms exceeded.

Axios Version

1.1.3

Adapter Version

No response

Browser

No response

Browser Version

No response

Node.js Version

14.19.3

OS

No response

Additional Library Versions

No response

Additional context/Screenshots

Related #4364.

@TechWizard9999
Copy link

😊 "I'd be delighted to work on issue! Could you please assign it to me?"

@isaachinman
Copy link

@WestonThayer Did you ever find an acceptable resolution to this problem?

@WestonThayer
Copy link
Author

We still don't rely on axios's timeout option, instead using our own setTimeout() with a axios.CancelToken. FWIW we'll probably migrate off axios to the fetch built into Node.js at some point.

@isaachinman
Copy link

Thanks for such a rapid response, even after a year and a half!

I've been doing more streaming recently, and have come to a similar conclusion. Axios is poorly suited for streaming, especially in client contexts, and even fetch has drawbacks.

I've taken to using raw XMLHttpRequest in many cases.

@n0th1ng-else
Copy link

I have switched to AbortSignal and it worked fine in my case. Dropped a short write up about the solution https://nothing-else.blog/blog/axios-timeout-for-chunked-responses

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants