Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture signal exits more than once #80

Open
erictheswift opened this issue Mar 25, 2024 · 0 comments
Open

Capture signal exits more than once #80

erictheswift opened this issue Mar 25, 2024 · 0 comments

Comments

@erictheswift
Copy link

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch signal-exit@4.1.0 for the project I'm working on.

I saw version 4.1.0 to

Add the ability to capture signal exits by returning true from the onExit listener.

and decided to try.
I found that capturing signal by returning true actually works only once — after first capture signal-exit eats it successfully but gets unloaded.

Here is the diff that solved my problem:

diff --git a/node_modules/signal-exit/dist/mjs/index.js b/node_modules/signal-exit/dist/mjs/index.js
index 4a78bad..3a289aa 100644
--- a/node_modules/signal-exit/dist/mjs/index.js
+++ b/node_modules/signal-exit/dist/mjs/index.js
@@ -61,13 +61,14 @@ class Emitter {
         if (this.emitted[ev]) {
             return false;
         }
-        this.emitted[ev] = true;
         let ret = false;
         for (const fn of this.listeners[ev]) {
             ret = fn(code, signal) === true || ret;
         }
+        this.emitted[ev] = !ret;
         if (ev === 'exit') {
             ret = this.emit('afterExit', code, signal) || ret;
+            this.emitted['afterExit'] = !ret;
         }
         return ret;
     }
@@ -139,6 +140,7 @@ class SignalExit extends SignalExitBase {
                     const s = sig === 'SIGHUP' ? this.#hupSig : sig;
                     if (!ret)
                         process.kill(process.pid, s);
+                    else this.load()
                     /* c8 ignore stop */
                 }
             };

This issue body was partially generated by patch-package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant