Unitech / Unitech/pm2

Can't configure wait_ready

Open
#5,632 3 comments 1 reaction 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?

Most likely me not understanding how to use wait_ready.
In this example app I've added 15s delay to start to simulate async loading of assets on load.
After starting the app I run pm2 reload pm2test and I would expect the app to be accessible through the whole time.
Instead there is a time window when I can't connect until the app loads fully

How could we reproduce this issue?

this is my config file:

module.exports = {
    apps: [
        {
            name: "pm2test",
            script: "dist/pm2ReloadTest.js",
            instances: "3",
            exec_mode: "cluster",
            autorestart: true,
            time: true,
            wait_ready: true,
           
        },
    ],
};

This is code for app

import express from "express";

const app = express();
const port = 3000;

app.get("/", (req, res) => {
    console.log("GET /");
    res.send("Hello World");
});

let server;
new Promise((resolve) => {
    setTimeout(resolve, 15000);
}).then(() => {
    server = app.listen(port, async () => {
        console.log(`Example app listening at http://localhost:${port}`);

        process.send("ready");
        console.log("ready");
    });
});

process.on("SIGTERM", () => {
    console.log("SIGTERM signal received: closing HTTP server");
    server.close(() => {
        console.log("HTTP server closed");
    });
});

Supporting information

Output from pm2 logs after running pm2 reload pm2test

PM2             | App [pm2test:0] starting in -cluster mode-
PM2             | App [pm2test:1] starting in -cluster mode-
PM2             | App [pm2test:0] online
PM2             | App [pm2test:1] online
PM2             | Stopping app:pm2test id:_old_0
PM2             | Stopping app:pm2test id:_old_1
PM2             | App name:pm2test id:_old_0 disconnected
PM2             | App [pm2test:_old_0] exited with code [0] via signal [SIGINT]
PM2             | App name:pm2test id:_old_1 disconnected
PM2             | App [pm2test:_old_1] exited with code [0] via signal [SIGINT]
PM2             | pid=78393 msg=process killed
PM2             | pid=78394 msg=process killed
PM2             | App [pm2test:2] starting in -cluster mode-
PM2             | App [pm2test:2] online
PM2             | Stopping app:pm2test id:_old_2
PM2             | App name:pm2test id:_old_2 disconnected
PM2             | App [pm2test:_old_2] exited with code [0] via signal [SIGINT]
PM2             | pid=79304 msg=process killed
0|pm2test       | 2023-07-06T10:00:35: Example app listening at http://localhost:3000
1|pm2test       | 2023-07-06T10:00:35: Example app listening at http://localhost:3000
1|pm2test       | 2023-07-06T10:00:35: ready
0|pm2test       | 2023-07-06T10:00:35: ready
2|pm2test       | 2023-07-06T10:00:41: Example app listening at http://localhost:3000
2|pm2test       | 2023-07-06T10:00:41: ready
$ pm2 report

PM2 | 2023-07-06T09:14:42: PM2 log: App [pm2test:_old_2] exited with code [0] via signal [SIGINT]
PM2 | 2023-07-06T09:14:42: PM2 log: pid=74020 msg=process killed
PM2 | 2023-07-06T10:00:20: PM2 log: App [pm2test:0] starting in -cluster mode-
PM2 | 2023-07-06T10:00:20: PM2 log: App [pm2test:1] starting in -cluster mode-
PM2 | 2023-07-06T10:00:23: PM2 log: App [pm2test:0] online
PM2 | 2023-07-06T10:00:23: PM2 log: App [pm2test:1] online
PM2 | 2023-07-06T10:00:26: PM2 log: Stopping app:pm2test id:_old_0
PM2 | 2023-07-06T10:00:26: PM2 log: Stopping app:pm2test id:_old_1
PM2 | 2023-07-06T10:00:26: PM2 log: App name:pm2test id:_old_0 disconnected
PM2 | 2023-07-06T10:00:26: PM2 log: App [pm2test:_old_0] exited with code [0] via signal [SIGINT]
PM2 | 2023-07-06T10:00:26: PM2 log: App name:pm2test id:_old_1 disconnected
PM2 | 2023-07-06T10:00:26: PM2 log: App [pm2test:_old_1] exited with code [0] via signal [SIGINT]
PM2 | 2023-07-06T10:00:26: PM2 log: pid=78393 msg=process killed
PM2 | 2023-07-06T10:00:26: PM2 log: pid=78394 msg=process killed
PM2 | 2023-07-06T10:00:26: PM2 log: App [pm2test:2] starting in -cluster mode-
PM2 | 2023-07-06T10:00:29: PM2 log: App [pm2test:2] online
PM2 | 2023-07-06T10:00:32: PM2 log: Stopping app:pm2test id:_old_2
PM2 | 2023-07-06T10:00:32: PM2 log: App name:pm2test id:_old_2 disconnected
PM2 | 2023-07-06T10:00:32: PM2 log: App [pm2test:_old_2] exited with code [0] via signal [SIGINT]
PM2 | 2023-07-06T10:00:32: PM2 log: pid=79304 msg=process killed

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

Reproduce the reload with the shown PM2 configuration and delayed Express app, using the PM2 logs and report output as the starting evidence. Trace the reload and wait_ready handling in the PM2 code, then verify that reloading all three instances does not leave a connection gap before the replacement workers are ready.

Written by the indexing model from the issue text.

Assessment

Tech stack
express, javascript, nodejs
Domain
devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.