Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling a looooong HTTP request (currently using axios)

I have a server that converts large files and uploads the results to cloud storage. Today I finally hit that limit, where conversion took over a minute and upload took 2 more, resulting in a very long HTTP request. Client is React using axios to call an Express server.

What I'm experiencing on the server side is that after about 2 minutes, the request gets called again (with no user input). Both requests then fail on the client (yet succeed on the server). The result is 2 conversions of the same file, and 2 useless uploads, since the client gets notified of an error.

I believe that what I'm seeing is a try-timeout-abort-retry-timeout-abort sequence. I tried passing a {timeout: 5 * 60 * 1000} to axios to get 5 minutes timeout - to no avail.

We're planning to change the process to be async, out-of-band, Web Sockets, etc. But until then, how can I ensure the request won't fail? Is there a browser-level setting I need to handle? Or use a different library than axios?

like image 291
Traveling Tech Guy Avatar asked Dec 31 '25 04:12

Traveling Tech Guy


1 Answers

Thanks to all the comments - you guys nailed it. The abort was issued by Express. Adding req.setTimeout(5 * 60 * 1000) solved it. Thanks all!

Update: adding the timeout at the server level is even better:

//...express middleware + routs + etc...
const server = app.listen(PORT, function() {
  console.log(`listening on ${PORT}`);
});

//set timeout of requests to 5 minutes
server.timeout = 5 * 60 * 1000;
like image 103
Traveling Tech Guy Avatar answered Jan 01 '26 16:01

Traveling Tech Guy