Unitech / Unitech/pm2

Starting stopped app using pm2.start overrides environment variables

Open
#4,896 0 comments 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?

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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.