Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pm2 is using asynchronous mode to create log directory, which may cause error when the folder is not exist #4844

Closed
QS20199 opened this issue Sep 7, 2020 · 1 comment

Comments

@QS20199
Copy link
Contributor

QS20199 commented Sep 7, 2020

What's going wrong?

pm2@4.4.1 is using asynchronous mode to create log folder, which may cause error when the program writing the log file firstly, and pm2 finishing creating the log folder secondly.

see https://github.com/Unitech/pm2/blob/4.4.1/lib/Common.js#L243, it's using async-mode to create dir, instead of sync-mode.

How could we reproduce this issue?

// index.js
console.log('start')
setInterval(() => {
        console.log('tick');
},1000);

and run:

pm2 start index.js -o ./a/very/long/path/which/is/not/exist/output.log 

and you will get the error:
image

Supporting information

--- PM2 report ----------------------------------------------------------------
Date : Mon Sep 07 2020 15:15:53 GMT+0800 (China Standard Time)

--- Daemon -------------------------------------------------
pm2d version : 4.4.1
node version : 12.18.3
node path : /usr/bin/pm2
argv : /usr/bin/node,/usr/lib/node_modules/pm2/lib/Daemon.js
argv0 : node
user : qsqiu
uid : 1000
gid : 1000
uptime : 185min

--- CLI ----------------------------------------------------
local pm2 : 4.4.1
node version : 12.18.3
node path : /usr/bin/pm2
argv : /usr/bin/node,/usr/bin/pm2,report
argv0 : node
user : qsqiu
uid : 1000
gid : 1000

--- System info --------------------------------------------
arch : x64
platform : linux
type : Linux
cpus : Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz
cpus nb : 8
freemem : 26491584512
totalmem : 26847076352
home : /home/qsqiu

--- PM2 list -----------------------------------------------
┌─────┬──────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user
│ watching │
├─────┼──────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0 │ index │ default │ N/A │ fork │ 1031 │ 3h │ 0 │ online │ 0.2% │ 42.7mb │ qsqiu
│ disabled │
└─────┴──────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘

--- Daemon logs --------------------------------------------
/home/qsqiu/.pm2/pm2.log last 20 lines:
PM2 | 2020-09-07T12:10:45: PM2 log: pid=923 msg=process killed
PM2 | 2020-09-07T12:10:45: PM2 log: PM2 successfully stopped
PM2 | 2020-09-07T12:10:46: PM2 log: ===============================================================================
PM2 | 2020-09-07T12:10:46: PM2 log: --- New PM2 Daemon started ----------------------------------------------------
PM2 | 2020-09-07T12:10:46: PM2 log: Time : Mon Sep 07 2020 12:10:46 GMT+0800 (China Standard Time)
PM2 | 2020-09-07T12:10:46: PM2 log: PM2 version : 4.4.1
PM2 | 2020-09-07T12:10:46: PM2 log: Node.js version : 12.18.3
PM2 | 2020-09-07T12:10:46: PM2 log: Current arch : x64
PM2 | 2020-09-07T12:10:46: PM2 log: PM2 home : /home/qsqiu/.pm2
PM2 | 2020-09-07T12:10:46: PM2 log: PM2 PID file : /home/qsqiu/.pm2/pm2.pid
PM2 | 2020-09-07T12:10:46: PM2 log: RPC socket file : /home/qsqiu/.pm2/rpc.sock
PM2 | 2020-09-07T12:10:46: PM2 log: BUS socket file : /home/qsqiu/.pm2/pub.sock
PM2 | 2020-09-07T12:10:46: PM2 log: Application log path : /home/qsqiu/.pm2/logs
PM2 | 2020-09-07T12:10:46: PM2 log: Worker Interval : 30000
PM2 | 2020-09-07T12:10:46: PM2 log: Process dump file : /home/qsqiu/.pm2/dump.pm2
PM2 | 2020-09-07T12:10:46: PM2 log: Concurrent actions : 2
PM2 | 2020-09-07T12:10:46: PM2 log: SIGTERM timeout : 1600
PM2 | 2020-09-07T12:10:46: PM2 log: ===============================================================================
PM2 | 2020-09-07T12:10:46: PM2 log: App [index:0] starting in -fork mode-
PM2 | 2020-09-07T12:10:46: PM2 log: App [index:0] online

This was referenced Sep 7, 2020
@Unitech
Copy link
Owner

Unitech commented Sep 29, 2020

published in pm2@4.5.0

npm install pm2@latest -g

@Unitech Unitech closed this as completed Sep 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants