Skip to content

fix: correct utility process exit code on Windows#50256

Merged
jkleinsc merged 2 commits intoelectron:mainfrom
Jomy2323:fix/utility-process-exit-code-windows
Mar 19, 2026
Merged

fix: correct utility process exit code on Windows#50256
jkleinsc merged 2 commits intoelectron:mainfrom
Jomy2323:fix/utility-process-exit-code-windows

Conversation

@Jomy2323
Copy link
Contributor

@Jomy2323 Jomy2323 commented Mar 13, 2026

On Windows, process exit codes are 32-bit unsigned integers (DWORD). When passed from Chromium to Electron as a signed int and then implicitly converted to uint64_t, values with the high bit set (e.g., NTSTATUS codes) undergo sign extension, producing incorrect values.

Cast the exit code to uint32_t before widening to uint64_t to prevent sign extension and preserve the original Windows exit code.

Fixes #49455

Description of Change

Earlier today I opened a PR for this issue, however, having used chat gpt to write its description, I'm afraid the electron bot tagged it as AI spam. That is not the case, the bug fix was a simple two line fix done by myself after investigating the cause. The problem was Chrome converts the windows error code from an unsigned 32 bit integer to a signed 32 bit integer, and then electron casts it to a 64 bit integer and does a sign extension. So for errors with highest bit set to 1 it will extend with 32 bits set to 1 on the left, giving us the unreal error codes. I ran the tests regarding the utilityProcess and all 55 tests passed.

Here you can see the print of the tests successfully passing:
image

Thanks for your attention and sorry to have bothered you earlier today.

Checklist

  • PR description included
  • I have built and tested this PR
  • npm test passes

Release Notes

Notes: Fixed utilityProcess exit event reporting incorrect exit codes on Windows when the exit code has the high bit
set.

@welcome
Copy link

welcome bot commented Mar 13, 2026

💖 Thanks for opening this pull request! 💖

Semantic PR titles

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:

  • fix: don't overwrite prevent_default if default wasn't prevented
  • feat: add app.isPackaged() method
  • docs: app.isDefaultProtocolClient is now available on Linux

Commit signing

This repo enforces commit signatures for all incoming PRs.
To sign your commits, see GitHub's documentation on Telling Git about your signing key.

PR tips

Things that will help get your PR across the finish line:

  • Follow the JavaScript, C++, and Python coding style.
  • Run npm run lint locally to catch formatting errors earlier.
  • Document any user-facing changes you've made following the documentation styleguide.
  • Include tests when adding/changing behavior.
  • Include screenshots and animated GIFs whenever possible.

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.

@electron-cation electron-cation bot added the new-pr 🌱 PR opened recently label Mar 13, 2026
@dsanders11
Copy link
Member

dsanders11 commented Mar 13, 2026

@Jomy2323, could you add test coverage for this case? Be sure to test high values on all platforms, and confirm the behavior is correct for each platform.

This change likely needs to be scoped to only do the static_cast for Windows.

@Jomy2323
Copy link
Contributor Author

@dsanders11, of course, ill look into that! Thank you for the review!

Copy link
Member

@deepak1556 deepak1556 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks the change is good, however I would prefer that the UtilityProcessWrapper::HandleTermination only takes uint32_t exit codes, there is no reason for it to require uint64_t, it must have been accidentally added due to UtilityProcessWrapper::Shutdown but that just has user generated success values. Its only OnServiceProcessCrashed or OnServiceProcessTerminatedNormally that return platform specific exit codes which is what we care about and the mojo disconnection already carries uint32_t for Node.js process exit codes OnServiceProcessDisconnected.

@Jomy2323
Copy link
Contributor Author

Okay, ill look into that. Thank you for your suggestion and feedback!

@deepak1556 deepak1556 self-requested a review March 16, 2026 10:30
@deepak1556 deepak1556 dismissed their stale review March 16, 2026 10:30

LGTM, pending CI

@jkleinsc jkleinsc added semver/patch backwards-compatible bug fixes target/40-x-y PR should also be added to the "40-x-y" branch. target/41-x-y PR should also be added to the "41-x-y" branch. target/42-x-y PR should also be added to the "42-x-y" branch. labels Mar 17, 2026
@electron-cation electron-cation bot removed the new-pr 🌱 PR opened recently label Mar 17, 2026
@jkleinsc jkleinsc added the needs-signed-commits Currently some or all of the commits in this PR are not signed label Mar 18, 2026
@jkleinsc
Copy link
Member

@Jomy2323 we require signed commits for our PRS: https://www.electronjs.org/docs/latest/development/pull-requests#commit-signing. Please sign your commits so that we can merge this PR.

On Windows, process exit codes are 32-bit unsigned integers (DWORD).
When passed from Chromium to Electron as a signed int and then
implicitly converted to uint64_t, values with the high bit set
(e.g., NTSTATUS codes) undergo sign extension, producing incorrect
values.

Cast the exit code to uint32_t before widening to uint64_t to
prevent sign extension and preserve the original Windows exit code.

Fixes electron#49455
@Jomy2323 Jomy2323 force-pushed the fix/utility-process-exit-code-windows branch from 826be53 to 440ae3f Compare March 19, 2026 11:04
@Jomy2323
Copy link
Contributor Author

@jkleinsc there you go. Thank you for your help!

@electron-issue-triage electron-issue-triage bot removed the needs-signed-commits Currently some or all of the commits in this PR are not signed label Mar 19, 2026
@jkleinsc jkleinsc merged commit 9ccc752 into electron:main Mar 19, 2026
181 of 186 checks passed
@welcome
Copy link

welcome bot commented Mar 19, 2026

Congrats on merging your first pull request! 🎉🎉🎉

@release-clerk
Copy link

release-clerk bot commented Mar 19, 2026

Release Notes Persisted

Fixed utilityProcess exit event reporting incorrect exit codes on Windows when the exit code has the high bit

@trop
Copy link
Contributor

trop bot commented Mar 19, 2026

I have automatically backported this PR to "42-x-y", please check out #50385

@trop trop bot removed the target/42-x-y PR should also be added to the "42-x-y" branch. label Mar 19, 2026
@trop
Copy link
Contributor

trop bot commented Mar 19, 2026

I have automatically backported this PR to "41-x-y", please check out #50386

@trop
Copy link
Contributor

trop bot commented Mar 19, 2026

I have automatically backported this PR to "40-x-y", please check out #50387

@trop trop bot added in-flight/41-x-y in-flight/40-x-y merged/42-x-y PR was merged to the "42-x-y" branch. merged/41-x-y PR was merged to the "41-x-y" branch. merged/40-x-y PR was merged to the "40-x-y" branch. and removed target/41-x-y PR should also be added to the "41-x-y" branch. target/40-x-y PR should also be added to the "40-x-y" branch. in-flight/42-x-y in-flight/41-x-y in-flight/40-x-y labels Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged/40-x-y PR was merged to the "40-x-y" branch. merged/41-x-y PR was merged to the "41-x-y" branch. merged/42-x-y PR was merged to the "42-x-y" branch. semver/patch backwards-compatible bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

utilityProcess exit event reports incorrect code on Windows

4 participants