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

unref() doesn't seem to work #16

Closed
Sidewinder1138 opened this issue Mar 25, 2016 · 3 comments
Closed

unref() doesn't seem to work #16

Sidewinder1138 opened this issue Mar 25, 2016 · 3 comments

Comments

@Sidewinder1138
Copy link

Opener is working great for launching my browser from my node script. But the problem I'm having is that if I kill node (via ctrl-c in the console), then my browser goes down with it! (In this case firefox on linux). I tried calling unref() like in your example but it doesn't seem to help, firefox just dies along with node.

I'm assuming that I'm doing something dumb, but could really use help figuring this out. Seems that everyone would want the child process to stay running, maybe that should be the default behavior?

@Sidewinder1138
Copy link
Author

OK I realize now that unref() only helps with the event loop. What I want is to set the "detached" option on the child process, so that even if Node goes down, the child (in my case firefox) stays up.

@jakub-g
Copy link
Contributor

jakub-g commented Mar 25, 2016

Hello @Sidewinder1138

IIRC I had this kind of issue with my module (biased-opener, which used to use opener, but since I switched to browser-launcher) and I solved it with:

                if (instance) {
                    instance.process.stdin.unref();
                    instance.stdout.unref();
                    instance.stderr.unref();
                    instance.process.unref();
                }

https://github.com/jakub-g/biased-opener/blob/master/index.js#L78-L83

Right now when the browser is opened, it becomes independent on the opening node process.

I also pass detached: true to browser-launcher2 so maybe you need to dig into it more if that is not enough

Hope that helps

@domenic
Copy link
Owner

domenic commented Sep 10, 2016

This seems pretty well-documented in the readme ("Plus, it returns the child process created, so you can do things like let your script exit while the window stays open:")

@domenic domenic closed this as completed Sep 10, 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

3 participants