Skip to content

Node behind nginx, giving 502 Bad Gateway after a few hours #804

@henit

Description

@henit
  • Node.js Version: 4.8.3
  • OS: Ubuntu 16.04
  • Express: 4.14.0
  • MongoDB: 3.4.5
  • PM2: 2.0.18

Express API application, running on Node behind Nginx. Have been running without problems for many months, then after a recent code update, it started giving 502 Bad Gateway. So probably caused by the code, but so far I have not been able to find the reason. This does NOT happen happen immediately after server start/restart, the API works without problems for a few hours, then it starts respoding with 502 until I restart the node application.

top-output the last time this happened (earlier today):

top - 07:54:23 up 4 days, 20:19,  3 users,  load average: 0.56, 0.59, 0.65
Tasks: 138 total,   1 running, 137 sleeping,   0 stopped,   0 zombie
%Cpu(s): 32.4 us,  6.3 sy,  0.0 ni, 58.7 id,  0.0 wa,  0.0 hi,  2.2 si,  0.3 st
KiB Mem :  4046688 total,  1000676 free,  1497976 used,  1548036 buff/cache
KiB Swap:        0 total,        0 free,        0 used.  2191124 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                  

21946 henrik    20   0 1605992 468336  17872 S  64.8 11.6 112:20.10 node
23390 mongodb   20   0 5948448 776540  29740 S  16.3 19.2 303:20.86 mongod

Nothing in the pm2 error output (or standard output) from node at the time when it occurs, but when I try to run requests towards the express API, nginx error logs:

2017/09/04 07:47:05 [error] 27938#27938: *10145 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 77.40.144.162, server: api.example.com, request: "GET /v0/path/123 HTTP/2.0", upstream: "http://127.0.0.1:8091/v0/path", host: "api.example.com", referrer: "http://example.com/"
2017/09/04 07:47:05 [error] 27938#27938: *10145 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 77.40.144.162, server: api.example.com, request: "GET /v0/path/123 HTTP/2.0", upstream: "http://127.0.0.1:8091/v0/path", host: "api.example.com", referrer: "http://example.com/"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions