nextjs configure to avoid http server timeout

Viewed 5627

I've a nextjs project proxied by nginx. I'm consuming a rest api served by nextjs itself that takes more than 2 minutes.

First error I get was 504 timeout by nginx so I added some additional directives:

proxy_connect_timeout 600s;
proxy_read_timeout 600s;
proxy_send_timeout 600s;
fastcgi_send_timeout 600s;
fastcgi_read_timeout 600s;

Then the error code becomes 502. Looking at proxy_error_log file the error is

 upstream prematurely closed connection while reading response header from upstream.

In my project I'm not using express or any other server explicitly so I don't know how to set http server timeout. Any way to set timeout from next.config.js file or globally for node js?

1 Answers

Answer from secret104278:

...this issue only occur in node12 but not in node14. This because default timeout in node12 is 2 minutes and there is no timeout in node14

The only way to get around this in next.js with node12 is using --http-server-default-timeout by something like NODE_OPTIONS='--http-server-default-timeout=0' next start

Hope this help anyone

Related