2

I have an application that runs into problems when 100+ items are being send to my nodejs backend for processing. The entire request can take up to 3 minutes due to external api call limits per minute.

I've tried both axios and superagent but both hit a timeout at 1-2 minutes and the frontend will error saying net::ERR_EMPTY_RESPONSE with axios and Error: Timeout exceeded at Request.push.RequestBase from superagent - but my backend will continue to process jobs and succeed.

In the express backend I've opened up the timeout to be 10 minutes following the advice here Nodejs and express server closes connection after 2 minutes.

I'm asking for advice as my only next thought would be to break up the results on my frontend and send many, smaller requests, to get the job done.

Thanks in advance for any help or advice.

Leslie Alldridge
  • 1,427
  • 1
  • 10
  • 26

1 Answers1

2

On axios you can set own timeout timer. Jus Initialize enter point:

const api = axios.create({
    baseURL: apiURL,
    timeout: 10 * 60 * 1000, // whatever time you want
});

and just use it like:

api.get()
api.post()
...
aturan23
  • 4,798
  • 4
  • 28
  • 52
  • Using that I'm now getting `xhr.js:178 POST http://localhost:3000/void net::ERR_EMPTY_RESPONSE` in my front end application after two minutes of waiting time. I've instantiated a new axios and made sure it's being used as you've recommended. Any further ideas on what it could be? Thanks – Leslie Alldridge Apr 21 '20 at 08:33
  • I am using create-react-app with a development proxy, will try set that to a higher amount. – Leslie Alldridge Apr 21 '20 at 08:44
  • @LeslieAlldridge I am at now using this functionality. maby mistakes from code. there you find official doc [example](https://github.com/axios/axios#axioscreateconfig) – aturan23 Apr 21 '20 at 09:08
  • 1
    I'll tick you as the answer because you are correct for development apps not using a create-react-app proxy. Turns out the CRA proxy is 2minutes set in stone, as soon as I built my app and served the static content without CRA it worked without any problems. – Leslie Alldridge Apr 21 '20 at 09:49
  • 1
    https://github.com/facebook/create-react-app/issues/3210 For anyone who stumbles across this thread in future, that GitHub issue lead me down the track of Create React App proxy being the problem, after trying to override it manually I just ran a production build and served `client/build/index.html` from my express server instead of running `npm run start` – Leslie Alldridge Apr 21 '20 at 09:50