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
fix: support async child process methods without callback in asar #15927
Conversation
💖 Thanks for opening this pull request! 💖 We use semantic commit messages to streamline the release process. Before your pull request can be merged, you should update your pull request title to start with a semantic prefix. Examples of commit messages with semantic prefixes:
Things that will help get your PR across the finish line:
We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems reasonable to me! It looks like most of this code was written by @kevinsawicki who's no longer maintaining Electron. Cc @alexeykuzmin for a second review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overrideAPI
is also called for fs.open
and fs.copyFile
, which require the callback to be passed.
As for child_process.execFile
, errors should be silently discarded when no callback is passed, currently overrideAPI
would try to invoke undefined
when path does not exist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In agreement with @zcbenz this will break the invalid usage of async APIs. Perhaps a canBeSync
flag passed to overrideAPI
might be the solution here
Looking closer, I don't think this has ever worked, the flow from async to sync ( If you look at the original code: Lines 165 to 176 in 90d1c0b
When there's no callback Lines 146 to 149 in 90d1c0b
I've introduced a more comprehensive change that passes a flag My change also means that we don't force the sync method on all further async calls, so if you didn't include a callback when calling once, it will allow you to use a callback in future invocations — there's an at-call check so it doesn't set The new code: Lines 146 to 180 in c58517f
All original and introduced asar tests pass. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with latest changes!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice change!
Release Notes Persisted
|
Congrats on merging your first pull request! 🎉🎉🎉 |
Description of Change
In Node land, async child process methods do not require a callback to be provided. In Electron land in the packaged asar environment, there's a bug which means if you don't provide a callback the method does not run — it runs synchronously and blocks execution when a long running child process is launched. I saw this with
execFile
, I had to add a callback to make the child process run.In development, original Node is used, but in production, Electron's Node (with changes) is used. This means there is a discrepancy between development and production environments and will catch users out, as it did to me. As it is a silent failure, it's quite difficult to spot.
This change no longer branches to call the synchronous method but continues to use the async method as requested and makes this flow work. I added a new asar test and all asar tests pass.
Checklist
npm test
passesRelease Notes
Notes: support async child process methods without callback in asar