-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Incorrect handling of SIGHUP #1667
Comments
I've not fully digested the change, but the pr you're referring to didn't change functionality, but added a feature that allowed a user to define the restart signal. Otherwise behaviour remained the same. If the user doesn't want to restart with As such, there's no coded handling in nodemon for But with that in mind, doesn't it render the issue as void? |
As I can see, the line 140 was added in the pr #1167: Lines 138 to 143 in f0c5353
If I understand it correctly, this is exactly handling of the restart signal. The
In fact, the default is that You are right that if user supplies |
May be it would be enough to just hardcode restart signal as SIGUSR2, regardless of what signal is sent to children. |
This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up. |
I don't think it should be marked stale |
This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up. |
Still not stale |
Since I still don't understand this PR and issue, I'm going to take the questions one at a time. Firstly:
Do you mean a) the signal sent from nodemon to the subprocess, or b) the signal that a user can send to nodemon? |
The answer is: Normal console tools (not daemons) should terminate on SIGHUP. And SIGHUP is what VS Code and ssh send on closing the terminal. |
This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up. |
Still not stale |
This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up. |
Still not stale |
I found this issue because it also gives me trouble. So now I have an "invisible" process running and if I try to start up a new dev session it says that the port I use is already in use. So what should happen in my specific case would be that PS stalebot is a bit aggressive IMHO. |
I’ve opened a new issue to discuss on proper signal handling. |
@remy, if you have more questions I would be glad to answer |
This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up. |
Still not stale |
I'm going to close this issue to continue discussion at #1705 - I'm close to getting my head around the potential problems and possible solution. I drew out a table of how nodemon and the subprocess is handling the signals and I think the way forward is to forward I'm also going to capture the points that @axxie has already brought up (the |
I think the implementation of handling of SIGHUP is not 100% correct.
The proper handling of SIGHUP is to terminate the application and its children, but nodemon restarts the child instead.
The changes in SIGHUP handling were introduced with PR #1167 (commit 30f999a). This commit introduced the feature to allow restarting child by sending SIGHUP to nodemon process. While the feature itself if fine, the choice of the signal, in my opinion, is not 100% correct. It think it would be better to always use SIGUSR2 for triggering restart. The details are below.
Expected behaviour
nodemon should terminate its child and itself upon receiving SIGHUP signal.
Actual behaviour
nodemon restarts the child.
Steps to reproduce
Use the following application:
With Visual Studio Code
signals-test.js
signals.log
in VS Code editor (it automatically reloads log file after changes). Alternatively, run the following command in another terminal:Notice the updates to
signals.log
file are restarted and continue from the background instance of the signals-test.js.With ssh
Notice the updates to
signals.log
file are restarted and continue from the background instance of the signals-test.js. Nodemon behaves likenohup
utility for applications launched in ssh session.Environment
nodemon: 2.0.2 (from sources in master)
node -v: v12.14.0
Operating system/terminal environment: Ubuntu 18.04.3 LTS
Analysis
According to
man 7 signal
, SIGHUP is sent when “Hangup detected on controlling terminal or death of controlling process”. Similar description can be found in Node documentation.Historically SIGHUP was useless for daemons because they have no controlling terminal. SIGHUP was then reused for triggering the reloading of daemon configs. However, the original handling is still valid and probably required for non-daemon apps, specifically, for applications started in the terminal.
How to test this behavior: run the sample code in the VS code terminal or via ssh directly, without nodemon. Then close the terminal or kill the client connection, just like described in the “Steps to reproduce section above”. Notice that the
signals.log
file is updated while terminal is open and updates stop when the terminal is closed. This is in the contrast to the launching the same code from under the nodemon.Proposed fix
I’ve made a PR with one variant of the fix. It contains the following changes:
Since this is a breaking change (though a minor one), I would like to propose alternative solutions:
Alternatively, the parameter can be used to switch to old (current) behavior.
The text was updated successfully, but these errors were encountered: