app.listen called on each request (pm2 / nodejs with nginx)
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 43.3k
- Forks
- 2.7k
- PR merge metrics
- No merged PRs in 30d
Description
Hello all,
I have make a little api on nodejs & express that is managed with pm2 and the entry point is managed with nginx.
for somes reasons I don't understand my application stopped randomly and not restart even if the watch option is specified.
When I'm looking logs I see a lot of console.log that are in my app.listen callback function. but no errors
Is it normal that on each request the app is relaunched and the callback app.listen called ?
few logs lines :
0|index | 2021-07-05T17:39:08: Example app listening on port 3000!
0|index | 2021-07-05T17:39:08: paiement endpoint -> https://api-xxxxx
0|index | 2021-07-05T17:40:39: Example app listening on port 3000!
0|index | 2021-07-05T17:40:39: paiement endpoint -> https://api-xxxxx
0|index | 2021-07-05T17:42:10: Example app listening on port 3000!
0|index | 2021-07-05T17:42:10: paiement endpoint -> https://api-xxxxx
0|index | 2021-07-05T17:43:41: Example app listening on port 3000!
0|index | 2021-07-05T17:43:41: paiement endpoint -> https://api-xxxxx
0|index | 2021-07-05T17:45:12: Example app listening on port 3000!
0|index | 2021-07-05T17:45:12: paiement endpoint -> https://api-xxxxx
0|index | 2021-07-05T17:46:42: Example app listening on port 3000!
my nginx configuration (i have comment somes line for test but no effect
server {
# listen *:80;
# listen [::]:80;
listen 443 ssl http2; #Nginx > 1.9.5
server_name api-xxxx.xxxx.fr;
location / {
proxy_pass http://localhost:3000;
# proxy_http_version 1.1;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header Host $host;
# proxy_set_header Upgrade $http_upgrade;
# proxy_set_header Connection "upgrade";
# proxy_set_header Access-Control-Allow-Origin $http_origin;
}
error_log /var/log/nginx/payement-api.log debug;
## Certificates
#ssl_certificate /etc/nginx/certificates/xxxx.pem;
#ssl_certificate_key /etc/nginx/certificates/xxx.rsa;
ssl_certificate /etc/nginx/certificates/xxx.pem;
ssl_certificate_key /etc/nginx/certificates/xxx.rsa;
ssl_trusted_certificate /etc/nginx/certificates/SectigoRSAOrganizationValidationSecureServerCA.crt;
## Protocol
ssl_protocols TLSv1.2;
## Diffie-Hellman
ssl_ecdh_curve secp384r1;
## Ciphers
ssl_ciphers "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA356 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH EDH+aRSA";
ssl_prefer_server_ciphers on;
# OCSP Stapling
resolver 80.67.169.12 80.67.169.40 valid=300s;
resolver_timeout 5s;
ssl_stapling on;
ssl_stapling_verify on;
## TLS parameters
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 5m;
ssl_session_tickets off;
## HSTS + headers
add_header Strict-Transport-Security "max-age=15552000; includeSubdomains; preload";
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header Content-Security-Policy "default-src 'self' *.xxxx.fr; img-src 'self' data: http: https: *.xxxx.fr; font-src 'self' data: http: https: fonts.googleapis.com";
add_header Cache-control "no-cache";
}
--- PM2 report ----------------------------------------------------------------
Date : Mon Jul 05 2021 18:47:32 GMT+0200 (GMT+02:00)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version : 4.4.0
node version : 10.19.0
node path : not found
argv : /usr/bin/node,/usr/lib/node_modules/pm2/lib/Daemon.js
argv0 : node
user : root
uid : 0
gid : 0
uptime : 0min
===============================================================================
--- CLI ----------------------------------------------------
local pm2 : 4.4.0
node version : 10.19.0
node path : /usr/bin/pm2
argv : /usr/bin/node,/usr/bin/pm2,report
argv0 : node
user : root
uid : 0
gid : 0
===============================================================================
--- System info --------------------------------------------
arch : x64
platform : linux
type : Linux
cpus : Intel(R) Xeon(R) CPU E5-2640 0 @ 2.50GHz
cpus nb : 2
freemem : 1368883200
totalmem : 3964522496
home : /root
===============================================================================
--- PM2 list -----------------------------------------------
┌─────┬──────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
├─────┼──────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 1 │ app │ default │ 0.0.0 │ fork │ 14233 │ 19s │ 0 │ online │ 0.3% │ 111.8mb │ root │ disabled │
│ 0 │ index │ default │ 1.0.0 │ fork │ 14227 │ 19s │ 0 │ online │ 0.3% │ 48.1mb │ root │ enabled │
└─────┴──────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------
/root/.pm2/pm2.log last 20 lines:
PM2 | 2021-07-05T18:47:12: PM2 log: --- New PM2 Daemon started ----------------------------------------------------
PM2 | 2021-07-05T18:47:12: PM2 log: Time : Mon Jul 05 2021 18:47:12 GMT+0200 (GMT+02:00)
PM2 | 2021-07-05T18:47:12: PM2 log: PM2 version : 4.4.0
PM2 | 2021-07-05T18:47:12: PM2 log: Node.js version : 10.19.0
PM2 | 2021-07-05T18:47:12: PM2 log: Current arch : x64
PM2 | 2021-07-05T18:47:12: PM2 log: PM2 home : /root/.pm2
PM2 | 2021-07-05T18:47:12: PM2 log: PM2 PID file : /root/.pm2/pm2.pid
PM2 | 2021-07-05T18:47:12: PM2 log: RPC socket file : /root/.pm2/rpc.sock
PM2 | 2021-07-05T18:47:12: PM2 log: BUS socket file : /root/.pm2/pub.sock
PM2 | 2021-07-05T18:47:12: PM2 log: Application log path : /root/.pm2/logs
PM2 | 2021-07-05T18:47:12: PM2 log: Worker Interval : 30000
PM2 | 2021-07-05T18:47:12: PM2 log: Process dump file : /root/.pm2/dump.pm2
PM2 | 2021-07-05T18:47:12: PM2 log: Concurrent actions : 2
PM2 | 2021-07-05T18:47:12: PM2 log: SIGTERM timeout : 1600
PM2 | 2021-07-05T18:47:12: PM2 log: ===============================================================================
PM2 | 2021-07-05T18:47:12: PM2 log: [Watch] Start watching index
PM2 | 2021-07-05T18:47:12: PM2 log: App [index:0] starting in -fork mode-
PM2 | 2021-07-05T18:47:12: PM2 log: App [app:1] starting in -fork mode-
PM2 | 2021-07-05T18:47:12: PM2 log: App [index:0] online
PM2 | 2021-07-05T18:47:12: PM2 log: App [app:1] online
thank you for you help
Jonathan
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reported app.listen callback logs, the nginx configuration, and the PM2 report, then determine whether requests are causing process restarts or whether PM2 is observing another condition. Done would require a reproducible cause and a confirmed resolution or clear explanation of the process lifecycle.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- express, javascript, nginx, nodejs
- Domain
- backend, devops
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100