Starting stopped app using pm2.start overrides environment variables
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?
I developed a failover script that is used to start or stop apps managed by PM2.
I start the failover script by running PORT=8000 node index.js. Problem is the apps managed by PM2 also use the PORT environment variable.
When the failover script runs pm2.start, PORT=8000 overrides the port that was set when initially starting apps (for example: PORT=8001 pm2 start /path/to/app1/index.js --name app1, PORT=8002 pm2 start /path/to/app2/index.js --name app2).
As a result, a port conflict error is thrown by Express.
How could we reproduce this issue?
This issue is difficult to easily reproduce. I will work on a proof of concept if need be.
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 failover script's index.js and the pm2.start call described in the report. Reproduce the differing PORT values with a minimal proof of concept, then verify that starting stopped apps preserves each app's configured environment instead of inheriting the caller's PORT.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- cli, devops
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100