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

Detecting end of work at end of forked process #255

Closed
jtlapp opened this issue Aug 19, 2016 · 3 comments
Closed

Detecting end of work at end of forked process #255

jtlapp opened this issue Aug 19, 2016 · 3 comments

Comments

@jtlapp
Copy link

jtlapp commented Aug 19, 2016

The standard wisdom for ending a node-forked process is to have either the parent or the child detect when the job is done and then explicitly end the child process. Unfortunately, I seem to have a situation where this conventional approach is not available.

I'm using the node-tap module within a fork to run tests. Most people do this by spawning a process, but I'm adding behavior that requires coordinating parent and child. I'd like to use IPC, so I'm forking.

Node-tap defers its work via process.nextTick() and who knows what else. I can't catch the end of work with a setImmediate(), as that happens too soon. It seems that I need to wait for node-tap to tell me that it's done.

But node-tap can't do that. The calling script essentially queues jobs (tests) with each call to node-tap, and node-tap can't know that no more jobs are forthcoming. The best it could possibly do is keep a count of jobs completed and give me that count. Node-tap is popular, and it seems that this feature wasn't needed for anything else, so it would have to be a special request to add support for my forking use-case.

I could solve this problem if node would just tell me when it would normally exit the process were it not forked, without actually exiting the process. "Hey, I'd normally be exiting now, but I'm not gonna, because you forked me." Then node-tap wouldn't need special support for forking.

Is there a way for me to do this? How do I detect the following condition?

  • The process has reached the end of the script AND there is no pending work to do.

Thanks for any help you can offer! (I'm working with the node-tap folks too.)

@addaleax
Copy link
Member

Something you may want to try is looking at what the (undocumented and not officially supported) process._getActiveHandles() and process._getActiveRequests() methods return (or their prettier wrapper, https://github.com/mafintosh/why-is-node-running), that should give you an idea of what keeps your process open.

And fyi, nodejs/node-v0.x-archive#2605 is no longer an issue with current Node versions – the IPC channel alone no longer keeps processes running.

@jtlapp
Copy link
Author

jtlapp commented Aug 19, 2016

Well, why-is-node-running is proving to be its own fight. I get the Cannot find module 'internal/linkedlist' error for not being compatible with node 5, and the --expose-internals solution cited here isn't working in my fork. I'm calling it a night. Thanks for your help!

@jtlapp
Copy link
Author

jtlapp commented Aug 19, 2016

I'm closing this because several methods have emerged for detecting the end of a node-tap run. Thanks for your help!

@jtlapp jtlapp closed this as completed Aug 19, 2016
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

2 participants