-
Notifications
You must be signed in to change notification settings - Fork 59
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
Child processes that don't die after SIGTERM are orphaned #87
Comments
In your killer module: Why aren't you just using the node api's Essentially in that function I'd like to handle the |
I just went in and modified the code in my node_modules to play around with it and calling After playing around with it I think that the module should just look like this: const KILL_SIGNAL = 'SIGTERM';
module.exports = function kill(child) {
return new Promise((resolve, reject) => {
child.on('close', resolve)
child.on('error', reject)
child.kill(KILL_SIGNAL)
});
} Unless there is a specific reason it was implemented with the custom kill behavior? I'd rather have lib_uv figure it out I guess. But at the very least I think it should be listening to EDIT: Nevermind 🤔 I see that its actually waiting for both the killer and the process in an outer kill function here https://github.com/gilamran/tsc-watch/blob/master/lib/runner.js#L21 So in that case I think that |
What would you suggest I should change? |
Well after looking at this pretty closely I think that tsc-watch is actually fine, not the one causing the "problem" for me. However, it did appear to be
These are both pretty optional, its not that tsc-watch has a bug its just that I couldn't tell where the issue was and it seemed like tsc-watch had the issue since it was controlling my process. Thanks for listening. |
Sounds good, How can I reproduce the "hanging" situation? |
in the app that is running if you implement a handler for 'SIGTERM' and never call process.exit() it will basically hang. // index.js
setInterval(() => console.log('still alive...'), 3000)
process.on('SIGTERM', () => console.log('SIGTERM received') Then tsc-watch will send the signal and wait for the process to exit which never happens. |
This might be related, when using |
I experienced similar problem, which can be reproduced with the following code: // index.ts
const id = setInterval(() => console.log('still alive...', process.pid), 3000);
process.on('SIGTERM', async () => {
console.log('SIGTERM received', process.pid);
await new Promise(resolve => {
setTimeout(() => {
clearInterval(id);
resolve();
}, 500);
});
}); Steps
Result, when save changes slowly |
How would you suggest fixing this? |
Sorry, I'm not familiar with the code base here, but I'll suggest something like:
I hope that make sense to you |
There has been some developments on this issue by the way, in some other repos where I also filed this bug (not knowing exactly where its originating from) it appears that it may be related to this source bug: Or possibly this library is experiencing a similar issue? Would be great if anyone here can add anything to that ticket. |
May be related to nodejs/node#34830 |
For me, the problem is related with handling // index.ts
const id = setInterval(() => console.log('still alive...', process.pid), 3000);
process.on('SIGTERM', () => {
console.log('SIGTERM received', process.pid);
clearInterval(id);
}); |
That's an interesting data point but even if you never called clearInterval, when the parent process closes this is supposed to be closed regardless of whether you handle SIGTERM or not, it should force it closed. |
I came across an issue today that seems to be related to this one, although slightly different. In my case, the process does die in response to The problem is that if two "compilation complete" events happen in quick succession, the I decided to have a go at fixing it, and have got a solution that seems to be working well, although I haven't had a chance to test it thoroughly yet. Before calling @gilamran, if you're open to it, I'd be happy to tidy up my fix, do some more testing on it, and put together a pull request. Incidentally, I also think we could improve the maintainability of this code by switching to Of course, my solution doesn't deal with the case where the process completely ignores |
@david-alexander regarding the issue you found, it sounds like something that needs to be fixed. Please do a PR and we'll talk about it there. (Thanks!) |
I'm having the same issue as @david-alexander where I end up with events happening too quickly and end up with multiple instances of the app running -- it's very frustrating :-/ Not meaning to complain, though, as this is still a great project and the best way (IMO) to use typescript in development; ts-node is too slow. |
Sorry I still haven't got round to doing a PR with my fix for this. @taxilian, have you tried the commit linked in my comment above to see if it fixes your issue? |
…lling processes after the last event. Fixes gilamran#87.
I have just taken another look at my fix today and have made a few changes to it - the new version is here.
|
…lling processes after the last event. Fixes gilamran#87.
I'm actually running into this with |
Can you please test with the next version? |
@gilamran hey Gil, this was my bad. This stopped happening once I instrumented the app to properly respond to a |
@gilamran, I believe I have been running into this same issue using When running my services with My problem appears to be resolved when using the latest However, I did run into a new problem with the v6 version. Running on a Mac, and working in a repo using yarn, I am getting this error when running
I got around it using the workaround here, but it seems the issue is likely a Windows CRLF in the executable node script for tsc-watch. |
@WadePeterson Thanks for trying out version 6! |
@WadePeterson published new |
Also, if everything is ok I'll publish v6 soon. |
Just installed |
Version 6 published! |
I'm using tsc-watch with a command like this:
In my application code I am handling
SIGTERM
like this:In that code I've discovered a bug which can result in the process never closing, never exiting. When this happens tsc-watch seems to just lose track of the process and not care about what happens. Later, if tsc-watch itself is killed that orphaned process continues running in the background forever.
It would be nice if tsc-watch would wait for the process to actually exit for a period of time, say 3 seconds? And if at that point it is still open then for it to send a second signal, say
SIGQUIT
?lerna run
with an error lerna/lerna#2284apollo-server
, ApolloServer.stop() can hang indefinitely waiting for connections to close (just like net.Server.close) apollographql/apollo-server#4097The text was updated successfully, but these errors were encountered: