egg-cluster icon indicating copy to clipboard operation
egg-cluster copied to clipboard

Graceful exit has not taken effect

Open anson09 opened this issue 1 year ago • 0 comments

Version: system: macOS 14.4.1 node: 20.12.2 "egg": "^3.17.5", "egg-cluster": "^2.2.1",

Minimal Code Example:

npx egg-init --type simple

// router.js
module.exports = app => {
  const { router, controller } = app;
  router.get('/', controller.home.index);

// add a router has a 3 seconds aysnc job
  router.get("/test", async (ctx) => {
    await new Promise((resolve) => {
      setTimeout(() => {
        resolve(1);
      }, 3000);
  });
  ctx.body = "test";
})

};

// index.js
const startCluster = require('egg-cluster').startCluster;

startCluster({
  baseDir: __dirname,
  workers: 2,
  port: 7001,
});
  1. start command: node index.js
  2. find node index.js pid in htop
  3. curl -v http://127.0.0.1:7001/api/v1/test
  4. send SIGTERM signal to pid filter in step 2

Expected: The request in step 3 has a successful response, EGG server closes after handling in transit connection.

Actually: the connection is closed immediately after the SIGTERM signal send.

anson09 avatar Apr 29 '24 08:04 anson09