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

child process spawned with child_process.fork cannot spawn an electron-shell #1613

Closed
golgobot opened this issue May 8, 2015 · 8 comments
Closed

Comments

@golgobot
Copy link

golgobot commented May 8, 2015

Sorry if I posted this in atom/atom. I realized this is an electron bug, not an Atom editor bug, so posting it here:

I have a example project to demonstrate the issue.

I'm trying to launch an electron shell from Atom. There's a bug in an electron shell spawned from a node process or from Atom or from electron itself where the rendering freezes. I've learned that if you double fork, ie spawn a process that spawns a detached process and then kill the middle process, the rendering bug does not occur.

This works great when spawned from iojs, but when spawned from Atom, the electron shell does not launch.

This is the code in render process of Atom

var child = fork('./child', [indexPath], {cwd: __dirname});
child.on('message', (message) => {
                //get pid to kill later
                pid = message.pid;
                child.kill('SIGINT');
                child = undefined;
            });

This is the code in child.js

var electronpath = require('../../node_modules/electron-prebuilt/index');
var child = spawn(electronpath, ['.'], { cwd: cwd, detached: true});
process.send({ pid: child.pid });

OSX Yosemite 10.10.1

@deepak1556
Copy link
Member

Thats because we create fork with ATOM_SHELL_INTERNAL_RUN_AS_NODE=1 env variable set, this passed to your spawn in child.js. Try disabling it in env parameter to workaround.

spawn(electronpath, ['.'], {env: {"ATOM_SHELL_INTERNAL_RUN_AS_NODE":"0"}, cwd: cwd});

@zcbenz what should we do about this scenario ?

@golgobot
Copy link
Author

golgobot commented May 8, 2015

Ok this worked. Thanks.

More about the freeze

The strange thing about the freeze is that it seems like JavaScript is still running. Sounds are playing as normal, But nothing seems to update visually, as if like the visual rendering is frozen. Electron also won't accept input. Mouse clicks don't work. If the dev tools are open I also lose the ability to interact with that. It happens very consistently with certain apps. Even to the point that it will freeze at exactly the same time every time.

@deepak1556
Copy link
Member

Can you provide a minimal sample app that demonstrates the freeze ? i tried using a few demos with your electron-bug repo with the env variable set, everything seems to work fine.

@golgobot
Copy link
Author

golgobot commented May 8, 2015

Sure thing. I'll update this comment when I have an example project.

@golgobot
Copy link
Author

Ok. Finally have a better answer to this question. I updated the example project to show how an electron shell that is spawned by an electron shell eventually freezes its rendering. The culprit seems to be console.log. If you call that over 200 times in a shell spawned from a shell, it freezes the rendering of that shell until that shell's parent is killed. Please read the README.md for more information on how to run the example.

@deepak1556
Copy link
Member

From iojs documentation,

When using the detached option to start a long-running process, the process will not stay running in the background unless it is provided with a stdio configuration that is not connected to the parent.

so you can either have {stdio: 'ignore'} or handle the preferred way you need.

@golgobot
Copy link
Author

Thanks.

On May 12, 2015, at 6:41 PM, Robo notifications@github.com wrote:

From iojs documentation,

When using the detached option to start a long-running process, the process will not stay running in the background unless it is provided with a stdio configuration that is not connected to the parent.
so you can either have {stdio: 'ignore'} or handle the preferred way you need.


Reply to this email directly or view it on GitHub.

@zcbenz
Copy link
Contributor

zcbenz commented May 20, 2015

Many node.js script spawns process.execPath to start a new Node.js process, so it is impossible to determine whether user wants to start Electron as Node.js or as normal Electron. But since it is very easy to work around this, I think current behavior is totally fine.

@zcbenz zcbenz closed this as completed May 20, 2015
bwinton added a commit to bwinton/tofino that referenced this issue Apr 13, 2017
The problem was that io doesn’t let us spawn child processes on Windows with the same stdio, as per electron/electron#1613 (comment), so let’s just ignore it in that specific case.
bwinton added a commit to bwinton/tofino that referenced this issue Apr 13, 2017
The problem was that io doesn’t let us spawn child processes on Windows with the same stdio, as per electron/electron#1613 (comment), so let’s just ignore it in that specific case.
victorporof pushed a commit to victorporof/tofino that referenced this issue Apr 14, 2017
The problem was that io doesn’t let us spawn child processes on Windows with the same stdio, as per electron/electron#1613 (comment), so let’s just ignore it in that specific case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants