Unitech / Unitech/pm2

Packages with / (slash) in name fails to reinstall / update

Open
#5,149 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
43.3k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Description

What's going wrong?

pm2 install @jessety/pm2-logrotate fails, when module already installed.

In https://github.com/Unitech/pm2/blob/master/lib/tools/copydirSync.js#L38 fs.mkdirSync(to); is called with the path to the module appended to the temporary os directory. The path is formed in https://github.com/Unitech/pm2/blob/master/lib/API/Modules/NPM.js#L434. There the module name @jessety/pm2-logrotate is treated as 2 path components, not as one.
Therefore the call to fs.mkdirSync(to); lacks the { recursive: true }-options argument, thus the call will fail.

How could we reproduce this issue?

run pm2 install @jessety/pm2-logrotate in cmd or from bat script.
then run pm2 install @jessety/pm2-logrotate in cmd or from bat script a second time. This step is Required to trigger the Rollback.backup function in https://github.com/Unitech/pm2/blob/master/lib/API/Modules/NPM.js#L430-L436.

Supporting information

Failing output sample

Windows
c:\web>pm2 install @jessety/pm2-logrotate
[PM2][Module] Installing NPM @jessety/pm2-logrotate module
[PM2][Module] Calling [NPM] to install @jessety/pm2-logrotate ...
+ @jessety/pm2-logrotate@2.7.4
added 206 packages from 252 contributors in 17.141s
[PM2][Module] Module downloaded
[PM2][WARN] Applications pm2-logrotate not running, starting...
[PM2] App [@jessety/pm2-logrotate] launched (1 instances)
Module: @jessety/pm2-logrotate
$ pm2 set @jessety/pm2-logrotate:max_size 100M
$ pm2 set @jessety/pm2-logrotate:compress true
$ pm2 set @jessety/pm2-logrotate:rotateInterval 0 0 * * 0
$ pm2 set @jessety/pm2-logrotate:dateFormat YYYY-MM-DD_HH-mm-ss
$ pm2 set @jessety/pm2-logrotate:retain 30
$ pm2 set @jessety/pm2-logrotate:rotateModule true
$ pm2 set @jessety/pm2-logrotate:workerInterval 30
Modules configuration. Copy/Paste line to edit values.
[PM2][Module] Module successfully installed and launched
[PM2][Module] Checkout module options: `$ pm2 conf`
┌─────┬───────────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name                      │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├─────┼───────────────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 2   │ app2                      │ default     │ 1.0.42  │ fork    │ 5576     │ 74m    │ 0    │ online    │ 0%       │ 6.2mb    │ Adm… │ disabled │
│ 1   │ app                       │ default     │ 1.0.42  │ fork    │ 5340     │ 74m    │ 0    │ online    │ 0%       │ 8.4mb    │ Adm… │ disabled │
└─────┴───────────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
Module
┌────┬──────────────────────────────┬───────────────┬──────────┬──────────┬──────┬──────────┬──────────┬──────────┐
│ id │ module                       │ version       │ pid      │ status   │ ↺    │ cpu      │ mem      │ user     │
├────┼──────────────────────────────┼───────────────┼──────────┼──────────┼──────┼──────────┼──────────┼──────────┤
│ 3  │ @jessety/pm2-logrotate       │ 2.7.4         │ 5888     │ online   │ 0    │ 0%       │ 21.9mb   │ Adm… │
└────┴──────────────────────────────┴───────────────┴──────────┴──────────┴──────┴──────────┴──────────┴──────────┘

c:\web>pm2 install @jessety/pm2-logrotate
[PM2][Module] Installing NPM @jessety/pm2-logrotate module
[PM2][Module] Module already installed. Updating.
internal/fs/utils.js:269
    throw err;
    ^

Error: ENOENT: no such file or directory, mkdir 'C:\Users\ADMINI~1\AppData\Local\Temp\2\@jessety\pm2-logrotate'
    at Object.mkdirSync (fs.js:921:3)
    at copydirSync (C:\npm\node_modules\pm2\lib\tools\copydirSync.js:38:14)
    at Object.backup (C:\npm\node_modules\pm2\lib\API\Modules\NPM.js:435:5)
    at C:\npm\node_modules\pm2\lib\API\Modules\NPM.js:170:16
    at moduleExistInLocalDB (C:\npm\node_modules\pm2\lib\API\Modules\NPM.js:162:10)
    at Object.install (C:\npm\node_modules\pm2\lib\API\Modules\NPM.js:166:3)
    at Object.Modularizer.install (C:\npm\node_modules\pm2\lib\API\Modules\Modularizer.js:48:9)
    at API.CLI.install (C:\npm\node_modules\pm2\lib\API\Modules\index.js:27:17)
    at Command.<anonymous> (C:\npm\node_modules\pm2\lib\binaries\CLI.js:501:9)
    at Command.listener (C:\npm\node_modules\pm2\node_modules\commander\index.js:315:8) {
  errno: -4058,
  syscall: 'mkdir',
  code: 'ENOENT',
  path: 'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\2\\@jessety\\pm2-logrotate'
}
--- PM2 report ----------------------------------------------------------------
Date                 : Fri Aug 13 2021 11:49:09 GMT+0200 (Central European Summer Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 5.1.0
node version         : 12.22.3
node path            : not found
argv                 : C:\Program Files\nodejs\node.exe,C:\npm\node_modules\pm2\lib\Daemon.js
argv0                : node
user                 : undefined
uid                  : N/A
gid                  : N/A
uptime               : 987min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 5.1.0
node version         : 12.22.3
node path            : not found
argv                 : C:\Program Files\nodejs\node.exe,C:\npm\node_modules\pm2\bin\pm2,report
argv0                : node
user                 : Administrator
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : win32
type                 : Windows_NT
cpus                 : Intel(R) Xeon(R) CPU E5-2686 v4 @ 2.30GHz
cpus nb              : 1
freemem              : 777043968
totalmem             : 2147074048
home                 : C:\Users\Administrator
===============================================================================
--- PM2 list -----------------------------------------------
┌─────┬───────────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name                      │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├─────┼───────────────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 2   │ app2                      │ default     │ 1.0.42  │ fork    │ 5576     │ 74m    │ 0    │ online    │ 0%       │ 6.0mb    │ Adm… │ disabled │
│ 1   │ app                       │ default     │ 1.0.42  │ fork    │ 5340     │ 74m    │ 0    │ online    │ 0.2%     │ 9.2mb    │ Adm… │ disabled │
└─────┴───────────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
Module
┌────┬──────────────────────────────┬───────────────┬──────────┬──────────┬──────┬──────────┬──────────┬──────────┐
│ id │ module                       │ version       │ pid      │ status   │ ↺    │ cpu      │ mem      │ user     │
├────┼──────────────────────────────┼───────────────┼──────────┼──────────┼──────┼──────────┼──────────┼──────────┤
│ 3  │ @jessety/pm2-logrotate       │ 2.7.4         │ 5888     │ online   │ 0    │ 0%       │ 35.7mb   │ Adm… │
└────┴──────────────────────────────┴───────────────┴──────────┴──────────┴──────┴──────────┴──────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------
C:\pm2\pm2.log last 20 lines:
PM2        | 2021-08-13T10:31:12: PM2 log: Stopping app:app id:1
PM2        | 2021-08-13T10:31:12: PM2 log: App [app:1] exited with code [1] via signal [SIGINT]
PM2        | 2021-08-13T10:31:13: PM2 log: pid=2140 msg=process killed
PM2        | 2021-08-13T10:31:13: PM2 log: Stopping app:app2 id:2
PM2        | 2021-08-13T10:31:13: PM2 log: App [app2:2] exited with code [1] via signal [SIGINT]
PM2        | 2021-08-13T10:31:13: PM2 log: pid=4484 msg=process killed
PM2        | 2021-08-13T10:34:53: PM2 log: App [app:1] starting in -fork mode-
PM2        | 2021-08-13T10:34:53: PM2 log: App [app2:2] starting in -fork mode-
PM2        | 2021-08-13T10:34:53: PM2 log: App [app2:2] online
PM2        | 2021-08-13T10:34:53: PM2 log: App [app:1] online
PM2        | 2021-08-13T11:43:29: PM2 log: Stopping app:pm2-logrotate id:0
PM2        | 2021-08-13T11:43:29: PM2 log: App [pm2-logrotate:0] exited with code [1] via signal [SIGINT]
PM2        | 2021-08-13T11:43:29: PM2 log: pid=2700 msg=process killed
PM2        | 2021-08-13T11:43:29: PM2 log: App [pm2-logrotate:0] starting in -fork mode-
PM2        | 2021-08-13T11:43:29: PM2 log: App [pm2-logrotate:0] online
PM2        | 2021-08-13T11:45:53: PM2 log: Stopping app:pm2-logrotate id:0
PM2        | 2021-08-13T11:45:53: PM2 log: App [pm2-logrotate:0] exited with code [1] via signal [SIGINT]
PM2        | 2021-08-13T11:45:53: PM2 log: pid=1852 msg=process killed
PM2        | 2021-08-13T11:49:01: PM2 log: App [@jessety/pm2-logrotate:3] starting in -fork mode-
PM2        | 2021-08-13T11:49:01: PM2 log: App [@jessety/pm2-logrotate:3] online

Unix
$ npx pm2 install @jessety/pm2-logrotate
[PM2] Spawning PM2 daemon with pm2_home=/Users/501/.pm2
[PM2] PM2 Successfully daemonized
[PM2][Module] Installing NPM @jessety/pm2-logrotate module
[PM2][Module] Calling [NPM] to install @jessety/pm2-logrotate ...

added 207 packages, and audited 208 packages in 8s

14 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
[PM2][Module] Module downloaded
[PM2][WARN] Applications pm2-logrotate not running, starting...
[PM2] App [@jessety/pm2-logrotate] launched (1 instances)
Module: @jessety/pm2-logrotate
$ pm2 set @jessety/pm2-logrotate:compress false
$ pm2 set @jessety/pm2-logrotate:dateFormat YYYY-MM-DD_HH-mm-ss
$ pm2 set @jessety/pm2-logrotate:max_size 10M
$ pm2 set @jessety/pm2-logrotate:retain 30
$ pm2 set @jessety/pm2-logrotate:rotateInterval 0 0 * * *
$ pm2 set @jessety/pm2-logrotate:rotateModule true
$ pm2 set @jessety/pm2-logrotate:workerInterval 30
Modules configuration. Copy/Paste line to edit values.
[PM2][Module] Module successfully installed and launched
[PM2][Module] Checkout module options: `$ pm2 conf`
┌─────┬───────────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name                      │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
└─────┴───────────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
Module
┌────┬──────────────────────────────┬───────────────┬──────────┬──────────┬──────┬──────────┬──────────┬──────────┐
│ id │ module                       │ version       │ pid      │ status   │ ↺    │ cpu      │ mem      │ user     │
├────┼──────────────────────────────┼───────────────┼──────────┼──────────┼──────┼──────────┼──────────┼──────────┤
│ 0  │ @jessety/pm2-logrotate       │ 2.7.4         │ 74164    │ online   │ 0    │ 0%       │ 67.7mb   │ 501      │
└────┴──────────────────────────────┴───────────────┴──────────┴──────────┴──────┴──────────┴──────────┴──────────┘

$ npx pm2 install @jessety/pm2-logrotate
[PM2][Module] Installing NPM @jessety/pm2-logrotate module
[PM2][Module] Module already installed. Updating.
internal/fs/utils.js:269
    throw err;
    ^

Error: ENOENT: no such file or directory, mkdir '/var/folders/5x/lgjjx5393hl1mj1vf5_9z7lc0000gn/T/@jessety/pm2-logrotate'
    at Object.mkdirSync (fs.js:921:3)
    at copydirSync (/Users/501/Documents/node_modules/pm2/lib/tools/copydirSync.js:38:14)
    at Object.backup (/Users/501/Documents/node_modules/pm2/lib/API/Modules/NPM.js:435:5)
    at /Users/501/Documents/node_modules/pm2/lib/API/Modules/NPM.js:170:16
    at moduleExistInLocalDB (/Users/501/Documents/node_modules/pm2/lib/API/Modules/NPM.js:162:10)
    at Object.install (/Users/501/Documents/node_modules/pm2/lib/API/Modules/NPM.js:166:3)
    at Object.Modularizer.install (/Users/501/Documents/node_modules/pm2/lib/API/Modules/Modularizer.js:48:9)
    at API.CLI.install (/Users/501/Documents/node_modules/pm2/lib/API/Modules/index.js:27:17)
    at Command.<anonymous> (/Users/501/Documents/node_modules/pm2/lib/binaries/CLI.js:501:9)
    at Command.listener (/Users/501/Documents/node_modules/pm2/node_modules/commander/index.js:315:8) {
  errno: -2,
  syscall: 'mkdir',
  code: 'ENOENT',
  path: '/var/folders/5x/lgjjx5393hl1mj1vf5_9z7lc0000gn/T/@jessety/pm2-logrotate'
}
--- PM2 report ----------------------------------------------------------------
Date                 : Fri Aug 13 2021 12:13:35 GMT+0200 (GMT+02:00)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 5.1.0
node version         : 12.22.1
node path            : /Users/501/Documents/node_modules/.bin/pm2
argv                 : /Users/501/.fnm/node-versions/v12.22.1/installation/bin/node,/Users/501/Documents/node_modules/pm2/lib/Daemon.js
argv0                : node
user                 : 501
uid                  : 501
gid                  : 20
uptime               : 7min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 5.1.0
node version         : 12.22.1
node path            : /Users/501/Documents/node_modules/.bin/pm2
argv                 : /Users/501/.fnm/node-versions/v12.22.1/installation/bin/node,/Users/501/Documents/node_modules/.bin/pm2,report
argv0                : node
user                 : 501
uid                  : 501
gid                  : 20
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : darwin
type                 : Darwin
cpus                 : Apple M1
cpus nb              : 8
freemem              : 21684224
totalmem             : 17179869184
home                 : /Users/501
===============================================================================
--- PM2 list -----------------------------------------------
┌─────┬───────────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name                      │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
└─────┴───────────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
Module
┌────┬──────────────────────────────┬───────────────┬──────────┬──────────┬──────┬──────────┬──────────┬──────────┐
│ id │ module                       │ version       │ pid      │ status   │ ↺    │ cpu      │ mem      │ user     │
├────┼──────────────────────────────┼───────────────┼──────────┼──────────┼──────┼──────────┼──────────┼──────────┤
│ 0  │ @jessety/pm2-logrotate       │ 2.7.4         │ 74164    │ online   │ 0    │ 0.3%     │ 119.8mb  │ 501   │
└────┴──────────────────────────────┴───────────────┴──────────┴──────────┴──────┴──────────┴──────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------
/Users/501/.pm2/pm2.log last 20 lines:
PM2        | 2021-08-13T12:05:45: PM2 log: ===============================================================================
PM2        | 2021-08-13T12:05:45: PM2 log: --- New PM2 Daemon started ----------------------------------------------------
PM2        | 2021-08-13T12:05:45: PM2 log: Time                 : Fri Aug 13 2021 12:05:45 GMT+0200 (GMT+02:00)
PM2        | 2021-08-13T12:05:45: PM2 log: PM2 version          : 5.1.0
PM2        | 2021-08-13T12:05:45: PM2 log: Node.js version      : 12.22.1
PM2        | 2021-08-13T12:05:45: PM2 log: Current arch         : x64
PM2        | 2021-08-13T12:05:45: PM2 log: PM2 home             : /Users/501/.pm2
PM2        | 2021-08-13T12:05:45: PM2 log: PM2 PID file         : /Users/501/.pm2/pm2.pid
PM2        | 2021-08-13T12:05:45: PM2 log: RPC socket file      : /Users/501/.pm2/rpc.sock
PM2        | 2021-08-13T12:05:45: PM2 log: BUS socket file      : /Users/501/.pm2/pub.sock
PM2        | 2021-08-13T12:05:45: PM2 log: Application log path : /Users/501/.pm2/logs
PM2        | 2021-08-13T12:05:45: PM2 log: Worker Interval      : 30000
PM2        | 2021-08-13T12:05:45: PM2 log: Process dump file    : /Users/501/.pm2/dump.pm2
PM2        | 2021-08-13T12:05:45: PM2 log: Concurrent actions   : 2
PM2        | 2021-08-13T12:05:45: PM2 log: SIGTERM timeout      : 1600
PM2        | 2021-08-13T12:05:45: PM2 log: ===============================================================================
PM2        | 2021-08-13T12:05:53: PM2 log: App [@jessety/pm2-logrotate:0] starting in -fork mode-
PM2        | 2021-08-13T12:05:53: PM2 log: App [@jessety/pm2-logrotate:0] online

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with lib/API/Modules/NPM.js around lines 430-436 and lib/tools/copydirSync.js around line 38, then reproduce the issue by installing @jessety/pm2-logrotate twice. Verify the reinstall or update succeeds on the reported Windows path, without the ENOENT mkdir error for the scoped package.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
cli, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.