From d7cfe08403d51f3eef1a1347616306ed29bdd439 Mon Sep 17 00:00:00 2001 From: Remy Sharp Date: Thu, 20 Jun 2024 09:06:40 +0100 Subject: [PATCH] docs: clarify how to handle SIGUSR2 Fixes #1889 --- README.md | 5 +++-- faq.md | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 851cfb3a..48054b19 100644 --- a/README.md +++ b/README.md @@ -292,9 +292,10 @@ nodemon sends a kill signal to your application when it sees a file update. If y The following example will listen once for the `SIGUSR2` signal (used by nodemon to restart), run the clean up process and then kill itself for nodemon to continue control: ```js -process.once('SIGUSR2', function () { +// important to use `on` and not `once` as nodemon can re-send the kill signal +process.on('SIGUSR2', function () { gracefulShutdown(function () { - process.kill(process.pid, 'SIGUSR2'); + process.kill(process.pid, 'SIGTERM'); }); }); ``` diff --git a/faq.md b/faq.md index 6209ccc7..f0425825 100644 --- a/faq.md +++ b/faq.md @@ -353,8 +353,10 @@ Your application will likely be running the old version code if you see that mes A common cause for this is when graceful shutdowns are doing async tasks, i.e: ``` -process.once('SIGUSR2', async () => { +// ensure this is `on` and not `once` +process.on('SIGUSR2', async () => { await db.disconnect() + process.kill(process.pid, 'SIGTERM'); }) ```