pm2 icon indicating copy to clipboard operation
pm2 copied to clipboard

PM2 throws errors when used with projects managed by GIT

Open thavus opened this issue 1 year ago • 6 comments

What's going wrong?

When I start any PM2 app, I see the following error, over and over. The server starts, errors then tries to restart.

PM2         | ===============================================================================
PM2         | --- PM2 global error caught ---------------------------------------------------
PM2         | Time                 : Fri Oct 20 2023 11:41:22 GMT-0400 (Eastern Daylight Time)
PM2         | The argument 'path' must be a string or Uint8Array without null bytes. Received 'C:\\Users\\Sean\\Documents\\Ream\\.git\\\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0...
PM2         | TypeError [ERR_INVALID_ARG_VALUE]: The argument 'path' must be a string or Uint8Array without null bytes. Received 'C:\\Users\\Sean\\Documents\\Ream\\.git\\\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0...
PM2         |     at Object.readFile (node:fs:393:10)
PM2         |     at Object.readFile (C:\Users\Sean\AppData\Roaming\npm\node_modules\pm2\node_modules\git-node-fs\lib\node-fs.js:18:10)
PM2         |     at Object.readRef (C:\Users\Sean\AppData\Roaming\npm\node_modules\pm2\node_modules\js-git\mixins\fs-db.js:62:8)
PM2         |     at resolveRef (C:\Users\Sean\AppData\Roaming\npm\node_modules\pm2\node_modules\js-git\mixins\walkers.js:104:8)
PM2         |     at onShallow (C:\Users\Sean\AppData\Roaming\npm\node_modules\pm2\node_modules\js-git\mixins\walkers.js:18:5)
PM2         |     at C:\Users\Sean\AppData\Roaming\npm\node_modules\pm2\node_modules\js-git\mixins\fs-db.js:89:7
PM2         |     at C:\Users\Sean\AppData\Roaming\npm\node_modules\pm2\node_modules\git-node-fs\lib\node-fs.js:23:12
PM2         |     at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3)
PM2         |     at FSReqCallback.callbackTrampoline (node:internal/async_hooks:130:17)
PM2         | ===============================================================================
PM2         | [PM2] Resurrecting PM2

How could we reproduce this issue?

Every time I've seen this error it occurred after I did a push to upstream with GIT. Afterwards, pm2 will start throwing errors related to GIT. I'm not using the watch feature. To confirm this is in fact the issue: When I moved the project's .git folder outside of the project, there's suddenly no problem at all.

Supporting information

--- PM2 report ----------------------------------------------------------------
Date                 : Fri Oct 20 2023 11:46:48 GMT-0400 (Eastern Daylight Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 5.3.0
node version         : 16.14.2
node path            : not found
argv                 : C:\Program Files\nodejs\node.exe,C:\Users\Sean\AppData\Roaming\npm\node_modules\pm2\lib\Daemon.js
argv0                : node
user                 : undefined
uid                  : N/A
gid                  : N/A
uptime               : 5min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 5.3.0
node version         : 16.14.2
node path            : not found
argv                 : C:\Program Files\nodejs\node.exe,C:\Users\Sean\AppData\Roaming\npm\node_modules\pm2\bin\pm2,report
argv0                : node
user                 : Sean
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : win32
type                 : Windows_NT
cpus                 : Intel(R) Core(TM) i7-10875H CPU @ 2.30GHz
cpus nb              : 16
freemem              : 22190993408
totalmem             : 34108944384
home                 : C:\Users\Sean
===============================================================================
--- PM2 list -----------------------------------------------
┌────┬─────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name        │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user
     │ watching │
├────┼─────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0  │ page-app    │ default     │ N/A     │ cluster │ N/A      │ 0      │ 0    │ stopped   │ 0%       │ 0b       │ Sean
     │ disabled │
│ 1  │ user-app    │ default     │ N/A     │ cluster │ N/A      │ 0      │ 0    │ stopped   │ 0%       │ 0b       │ Sean
     │ disabled │
└────┴─────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------
C:\Users\Sean\.pm2\pm2.log last 20 lines:
PM2        | 2023-10-20T11:41:26: PM2 log: ===============================================================================
PM2        | 2023-10-20T11:41:26: PM2 error: [PM2] Resurrecting PM2
PM2        | 2023-10-20T11:41:26: PM2 log: pid=25252 msg=process killed
PM2        | 2023-10-20T11:41:27: PM2 log: PM2 successfully stopped
PM2        | 2023-10-20T11:41:27: PM2 log: ===============================================================================
PM2        | 2023-10-20T11:41:27: PM2 log: --- New PM2 Daemon started ----------------------------------------------------
PM2        | 2023-10-20T11:41:27: PM2 log: Time                 : Fri Oct 20 2023 11:41:27 GMT-0400 (Eastern Daylight Time)
PM2        | 2023-10-20T11:41:27: PM2 log: PM2 version          : 5.3.0
PM2        | 2023-10-20T11:41:27: PM2 log: Node.js version      : 16.14.2
PM2        | 2023-10-20T11:41:27: PM2 log: Current arch         : x64
PM2        | 2023-10-20T11:41:27: PM2 log: PM2 home             : C:\Users\Sean\.pm2
PM2        | 2023-10-20T11:41:27: PM2 log: PM2 PID file         : C:\Users\Sean\.pm2\pm2.pid
PM2        | 2023-10-20T11:41:27: PM2 log: RPC socket file      : \\.\pipe\rpc.sock
PM2        | 2023-10-20T11:41:27: PM2 log: BUS socket file      : \\.\pipe\pub.sock
PM2        | 2023-10-20T11:41:27: PM2 log: Application log path : C:\Users\Sean\.pm2\logs
PM2        | 2023-10-20T11:41:27: PM2 log: Worker Interval      : 30000
PM2        | 2023-10-20T11:41:27: PM2 log: Process dump file    : C:\Users\Sean\.pm2\dump.pm2
PM2        | 2023-10-20T11:41:27: PM2 log: Concurrent actions   : 2
PM2        | 2023-10-20T11:41:27: PM2 log: SIGTERM timeout      : 1600
PM2        | 2023-10-20T11:41:27: PM2 log: ===============================================================================

thavus avatar Oct 20 '23 15:10 thavus

Uhhh when I moved the project's .git folder outside of the project, there's suddenly no problem at all. Why? I'm so confused. Why is PM2 dipping into my .git folder? Updated the issue report with this info.

My servers are located in a child folder of my main project folder, while my .git folder is located in the parent project folder. I have no idea how pm2 is traversing up several folders outside the scope of my applications and then dipping into the .git folder.

thavus avatar Oct 20 '23 15:10 thavus

Here is how I fixed this problem for myself.

  1. End all PM2 processes.
  2. git remote rm origin to remove the origin from git.
  3. git remote add origin UrlOfYourOrigin
  4. Important: Restart your PC.
  5. You should be able to start PM2 now.

EDIT: This actually does not work. I'm having this problem again months later and these steps are not working. I'm not sure what I did last time to resolve it but my only solution now was to create a powershell script to move my .git folder outside of the project so pm2 doesn't have a seizure.

thavus avatar Oct 24 '23 15:10 thavus

Several months later, I'm having this problem again and the steps I used before don't seem to be resolving the issue. The only thing that works is to remove .git folder from my project entirely. Once again, the problem started occuring randomly without much reason why it has happened. I did do a push to my git repo before I logged off last Friday. But why is PM2 messing with my .git folder?

I'm not using the watching feature of pm2. I also tried including the "ignore_watch" parameter with '\.git' added to my ecosystem and the issue still occurred.

thavus avatar Mar 11 '24 21:03 thavus

I tried setting watch to false for all apps in my ecosystem and the issue persists.

thavus avatar Mar 11 '24 21:03 thavus

... my fix was I made a powershell script to move .git to my desktop before the pm2 start eco runs .... jesus christ what a shit show.

thavus avatar Mar 11 '24 22:03 thavus

Updated the details of this bug to better reflect the problem in case anyone looks at this in the future.

thavus avatar Mar 11 '24 22:03 thavus