Getting 504 GATEWAY_TIMEOUT NodeJs

I get a 504 GATEWAY_TIMEOUT http response after 60 seconds of page loading.

This is not the actual page that is being loaded than the process that is being executed. I expect this to take more than 60 seconds, and I tried to increase the timeout value, but that didn't help.

I use the express framework for routing, and I accept the job on EB (AWS Elastic Beanstalk). Since I increased all the timeout values ​​that I could find on EB and Load Balancers in the AWS console, I assume that this should be the application itself, which has a timeout of up to 60 seconds. However, maybe I'm wrong.

My code is:

 /* GET home page. */ router.get('/main',function(req, res, next) { req.connection.setTimeout(600000); mainProcess(res); //res.send("mainProcess() called"); }); 

UPDATE:

Also, I tried a different approach. I added this code in app.js :

 var connectTimeout = require('connect-timeout'); var longTimeout = connectTimeout({ time: 600000 }); app.use(longTimeout); 

Did not help.

UPDATE2: I also tried increasing the timeout in /bin/www as follows:

 var server = http.createServer(app); server.timeout=600000; 

Update3: I noticed that the timeout is related to the nginx configuration. As my logs say: upstream timed out (110: Connection timed out) while reading response header However, I cannot find a way to edit the nginx configuration on an elastic beanstalk. I did some research, but it all seems to me non-standard and too tough for such a simple thing.

+6
source share
4 answers

Usually, when a task takes more than 30 seconds or 40 seconds, I usually notify the user who is executing, and then create a process for working with the database instead of the usual server request so that the user does not wait for the request and avoid this timeout problem, you can try this, for example, when you install the server to listen on the specified port:

 //Create server with specified port var server = app.listen(app.get('port'), function() { debug('Express server listening on port ' + server.address().port); }); //set timeout time server.timeout = 1000; 
+2
source

In your .ebextensions add the following code:

  container_commands: change_proxy_timeout: command: | sed -i '/\s*location \/ {/c \ location / { \ proxy_connect_timeout 300;\ proxy_send_timeout 300;\ proxy_read_timeout 300;\ send_timeout 300;\ ' /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf 
+2
source

From your Update3 information, I think you need to configure the nginx configuration file, for example:

 server { listen 80; server_name *.*; location / { proxy_pass http://192.168.0.100:8001; proxy_connect_timeout 60s; proxy_read_timeout 5400s; proxy_send_timeout 5400s; proxy_set_header host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Real-IP $remote_addr; proxy_redirect default; } } 

proxy_read_timeout and proxy_send_timeout are related to your problem.

0
source

I had the same problem, so I tried to set timeout = 120000 as follows:

 var server= http.createServer(app).listen(port, function() { console.log("Express server listening on port " + port) }) server.timeout = 120000; 
0
source

All Articles