electron: [Bug]: Spawning and unreferencing a child process prevents electron from exiting
Preflight Checklist
- I have read the Contributing Guidelines for this project.
- I agree to follow the Code of Conduct that this project adheres to.
- I have searched the issue tracker for a bug report that matches the one I want to file, without success.
Electron Version
19.0.7
What operating system are you using?
Other Linux
Operating System Version
Debian 10 (buster)
What arch are you using?
arm64 (including Apple Silicon)
Last Known Working Electron version
No response
Expected Behavior
Running the following:
spawn('sleep', ['10'], {
detached: true,
stdio: 'ignore',
}).unref();
should allow Electron to exit without waiting for the child process.
Actual Behavior
Electron emits the correct events, however some electron processes linger until the child process has completed.
Testcase Gist URL
https://gist.github.com/Josh-G/aadee165b50c7629d5f1c9340728a8ca
Additional Information
I’ve also created a repo with a workflow that demonstrates the issue; https://github.com/Josh-G/electron-spawn-detached
I believe this may be the same as, or a regression of, https://github.com/electron/electron/issues/2208 https://github.com/electron/electron/issues/13870. I’ve reproduced this on Linux on arm64 + x64 with Debian and Ubuntu (thru GitHub Action).
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 4
- Comments: 20 (8 by maintainers)
Anyway we can turn off the “Stale” bot on this issue?
This issue still affects the latest Electron, I’m still using the workaround here https://github.com/electron/electron/issues/34808#issuecomment-1275530924 by p120ph37
The issue is that Chrome/Electron leaks open file-descriptors into the child-process. For one reason or another, these open file-descriptors being held by the child-process are keeping parts of Electron from exiting until they are closed. Try looking at the
/proc/$PID/fd
filesystem for the child-process, and you will see all of the inherited open descriptors. The general problem was discussed here, and is in a wont-fix status: https://github.com/electron/electron/issues/1447One way around this is to loop over all the open file-descriptors that your child-process has inherited and close them all. (of course it would be better if Electron were to provide this functionality in the
child_process
functions directly…)Below is a wrapper which accomplishes this with some bash magic:
I received the following similar error “white screen” when running
element-desktop --enable-logging
on a Nvidia GPU GTX 1080. All this 💩 javascript; no one seems to know how to code with C++ anymore 😢 .I build my applications with GTK 4 (C/C++) in parallel with a nice UI named Cambalache.
Electron Version: electron29-29.3.1-1 Operating System: Arch Linux
So many npm/nodejs monsters nowadays.
Anyone have any recommendations for a client built with non-js 💩 ? JS is a security nightmare to begin with and am humored by all the js being used for secure messaging app…electron is a bloated piece of yuk imo and should rarely be used for a professional application.
A fresh init of element-desktop with electron-29 💩
I’ve tried electron 20-x-y and the 21 alpha, just in case there was any change, without success.