1

I'm encountering a problem with http requests in my React/Nodejs app. When I'm trying to do a request that takes a long time (like 4 minutes or more) before sending response to the client the request is aborted. Is there any timeout for requests or something I'm not considering? That's the response of my POST request: Failed to load resource: net::ERR_EMPTY_RESPONSE

Is there maybe something to handle with AbortController?

Flavio Del Grosso
  • 490
  • 2
  • 7
  • 21

1 Answers1

0

EDIT: Reviewed my answer title to center the problem. I found a solution using setTimeout() in my Express.js. The problem was due to a server abort by the default express timeout.

I added this code in my server to resolve it. Hope this is usefull for someone:

const timeOut = 1000 * 60 * 10;
app.use((req, res, next) => {
    req.setTimeout(timeOut, () => {
        const error = new Error('Request Timeout.');
        err.status = 408;
        next(error);
    });
    res.setTimeout(timeOut, () => {
        const error = new Error('Request has expired.');
        err.status = 503;
        next(error);
    })
    next();
});
Flavio Del Grosso
  • 490
  • 2
  • 7
  • 21