Consequences of using kill -9 for node processes?

When reading mongodb documentation, one of the distinguishing features:

Attention

Never use kill -9 (i.e. SIGKILL) to terminate a mongod instance.

I'm having trouble using foreman start to start my node server. Foreman will start several node processes with the same PID.

However, the problem is that when I stop my node process, the node does not actually stop and continues to use the port that it was listening to.

To get around this, I used sudo kill -9 <PID> for the node process that I want to terminate. Are there any negative consequences to this?

Also, why does Mongo warn about using kill -9 to terminate a mongod instance?

+7
linux mongodb
source share
2 answers

This does not allow this process to:

1) disable socket connections

2) cleaning temporary files

3) tell your children that he is leaving

4) reset its final characteristics

These are bad consequences of what might happen when you use kill -9 . You should use kill -9 as a last resort if all else fails.

And to the second question, because kill -9 will kill the process, even if it is in the middle of something, and kill will shut down the process after a clean exit.

+5
source share

Using SIGKILL ( -9 ) instead of the more general SIGTERM (without parameters) or SIGHUP ( -1 ) means that the process has been killed at the OS level. Mongo stores a lot of data in memory in the form of a cache, both for reading and writing. Therefore, using SIGKILL may mean that the data was half written to disk or never will be written at all. In any case, you can get a damaged database or get missing data that was transferred to users or other processes as successfully saved. Classical database systems work around this issue with transaction logs (kernel panic or power failure is essentially the same effect), but Mongo is considered nosql for good reasons, including but not limited to transaction integrity.

This, of course, applies only to the server process, you can kill your node processes in any way that you want from the point of view of mongo. However, in the general case, you should avoid using kill -9 to kill any process for the same reasons that were outlined above. Processes that cannot be cleaned tend to leave a mess. The usual order:

 kill <pid> 

... Sends SIGTERM , requesting a graceful shutdown, so wait 30 seconds for the process to close if it is still alive:

 kill -1 <pid> 

... Sends SIGHUP , requesting an immediate shutdown, wait another 30 seconds, at least to complete the process, and finally:

 kill -9 <pid> 

... If and only if , the process cannot be continued because it causes problems in server stability or resource blocking. In all other cases, just wait.

Regarding the differences between the “graceful” and the “immediate” shutdowns mentioned above, consider having notepad.exe in which you typed 2 lines. An elegant dialog box pops up asking if you want to save it, it immediately turns off without user intervention, and kill immediately stops the process and frees all memory and other resources back to the system. Historically, signals come from old universal mainframes, where SIGHUP is short for "Hangup", indicating that the user has left and cannot return.

+2
source share

All Articles