13

I’m been scratching my head on this timeout issue and hope to get some helps. I have a http request that might take 2.5 minutes to return the response. I have timeout handling in Angular for 3 minutes, and NodeJS for 3 minutes as well. My nginx setting have 200 seconds timeout and my Elastic Load Balancing Connection Timeout is set to 4 minutes. However, I keep seeing the 502 bad gateway nginx 1.4.6 (Ubuntu) error at exact 2 minutes. Is there any part that I miss to have longer timeout?

My nginx setting:

server {
    listen 80;
    server_name;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log debug;
    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_set_header Connection "";
        proxy_http_version 1.1;
        proxy_pass http://localhost:8060;
        proxy_redirect off;
        proxy_connect_timeout 200s;
        proxy_send_timeout 200s;
        proxy_read_timeout 200s;
        send_timeout 200s;
    }
    #Handle protected assets using 'internal' directive documented here: https://www.nginx.com/resources/wiki/start/topics/examples/x-accel/
    location /protected {
        internal;
        expires -1;
    }
}

My NodeJS setting is using connect-timeout

var timeout = require('connect-timeout');
app.use(timeout(300000));
3
  • Have you tried setting the keepalive, client_header and client_body timeouts? Commented Jul 29, 2016 at 12:37
  • Yeah, I've tried those and still have the same issue. Commented Jul 29, 2016 at 21:48
  • Did you ever figure this out? Commented Feb 9, 2017 at 20:34

1 Answer 1

13

I just came across this today, and probably found an answer - there is 120 s hard coded timeout in node's http module. I had to set socket timeout in given request handler like this:

yourHandler(req, res) {
  req.socket.setTimeout(3600e3); // 1 hour

  // ... do the real work

  res.json(...);
}

You can also set this limit to 0 to disable this timeout.

https://nodejs.org/api/net.html#net_socket_settimeout_timeout_callback

originally found the answer here: https://forum.nginx.org/read.php?2,214230,214239#msg-214239

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.