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

It does not catch 'nodemon' reload. #31

Open
Zirafnik opened this issue May 13, 2023 · 3 comments
Open

It does not catch 'nodemon' reload. #31

Zirafnik opened this issue May 13, 2023 · 3 comments

Comments

@Zirafnik
Copy link

The hook does not catch 'nodemon' reloads. I am not sure if this is by design or not.

@jpmnteiro
Copy link

@Zirafnik nodemon sends a SIGUSR2 by default (see remy/nodemon#1098).

Looking at the source code for this package, it doesn't seem to register a handler for that signal, so I suspect it's relying on the exit (or beforeExit) hooks.

@sindresorhus
Copy link
Owner

sindresorhus commented Aug 31, 2023

I don't think we can simply register a handler for SIGUSR2, because the wanted behavior of the signal is sender-defined. To support it by default, we would have to be able to detect that the signal came from nodemon, which I'm not sure is possible in Node.js.

One way to solve this would be to get nodemon to set a certain environment variable that we could check.

// @jakobo

@thecodedrift
Copy link
Contributor

thecodedrift commented Aug 31, 2023

Looking at the source code for this package, it doesn't seem to register a handler for that signal, so I suspect it's relying on the exit (or beforeExit) hooks.

That's correct. As Sindre said, SIGUSR2 is a userland signal, which means we cannot act on it. The signal data doesn't include parent processes either.

If you don't need asynchronous support, you can just change nodemon's signal via nodemon --signal to SIGINT or SIGTERM which would be sufficient.

On the asynchronous side, I'm hesitant to make responding to SIGTERM perform asynchronous cleanup. In practice, despite it being for polite termination, end developers do not hold that expectation.

A better option would be if nodemon could support --signal message which would send the signal identifier via IPC. This is how PM2 works in environments that don't support signaling. We then handle process.on("message", ...) and can shut down gracefully.

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

4 participants