Skip to content

[vm] Allow to skip crash handler installation in bin::Platform::Initialize.#62680

Closed
Arbaaz123676 wants to merge 2 commits into
dart-lang:mainfrom
Arbaaz123676:fix-macos-sigpipe-process-start
Closed

[vm] Allow to skip crash handler installation in bin::Platform::Initialize.#62680
Arbaaz123676 wants to merge 2 commits into
dart-lang:mainfrom
Arbaaz123676:fix-macos-sigpipe-process-start

Conversation

@Arbaaz123676

Copy link
Copy Markdown
Contributor

Summary

On macOS, writing to a closed exit pipe can deliver SIGPIPE which terminates the process even when EPIPE is handled correctly.

This change temporarily blocks SIGPIPE while writing the exit code in "ExitCodeHandlerEntry". This ensures that failed "Process.start" calls do not trigger unintended process termination.

The signal mask is scoped only around the write operation to keep the behaviour localized and avoid affecting global signal handling.

Platform: macOS only

Fixes: #62679.

@copybara-service

Copy link
Copy Markdown

Thank you for your contribution! This project uses Gerrit for code reviews. Your pull request has automatically been converted into a code review at:

https://dart-review.googlesource.com/c/sdk/+/480880

Please wait for a developer to review your code review at the above link; you can speed up the review if you sign into Gerrit and manually add a reviewer that has recently worked on the relevant code. See CONTRIBUTING.md to learn how to upload changes to Gerrit directly.

Additional commits pushed to this PR will update both the PR and the corresponding Gerrit CL. After the review is complete on the CL, your reviewer will merge the CL (automatically closing this PR).

@mraleph

mraleph commented Feb 15, 2026

Copy link
Copy Markdown
Member

There is already code in Platform::Initialize which does this. I would expect it is called by Flutter engine. This means something later messes it up.

@Arbaaz123676

Copy link
Copy Markdown
Contributor Author

Hi @mraleph, Thanks for the pointer! That makes sense — I added the masking here because I observed SIGPIPE during the exit pipe write path on macOS, but if Platform::Initialize already configures it, then something later must be modifying the mask.

I’ll investigate where SIGPIPE handling may be reset after initialization. Do you have a recommended area to check (Flutter embedder vs VM runtime), or should I go with tracing signal mask changes around process start?

Happy to adjust the approach based on the intended design.

@mraleph

mraleph commented Feb 16, 2026

Copy link
Copy Markdown
Member

See my comment here: #62679 (comment)

@copybara-service

Copy link
Copy Markdown

https://dart-review.googlesource.com/c/sdk/+/480880 has been updated with the latest commits from this pull request.

1 similar comment
@copybara-service

Copy link
Copy Markdown

https://dart-review.googlesource.com/c/sdk/+/480880 has been updated with the latest commits from this pull request.

Comment thread runtime/bin/platform_macos.cc Outdated
if (sigaction(SIGILL, &act, nullptr) != 0) {
perror("sigaction() failed.");
return false;
if (install_crash_handler){

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not properly formatted: missing space here.

In general, I'd recommend running git cl format to make sure that all code is properly formatted.

Comment thread runtime/bin/process_macos.cc Outdated
int message[2] = {exit_code, negative};
ssize_t result =
FDUtils::WriteToBlocking(exit_code_fd, &message, sizeof(message));
ssize_t result =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fully revert changes to this file as they are not necessary.

@mraleph

mraleph commented Feb 16, 2026

Copy link
Copy Markdown
Member

The title of this PR should probably be updated to match what we are doing here.

@Arbaaz123676 Arbaaz123676 changed the title [vm] Mask SIGPIPE during exit pipe write on macOS. [vm] Respect install_crash_handler in Platform::Initialize on macOS. Feb 16, 2026
@copybara-service

Copy link
Copy Markdown

https://dart-review.googlesource.com/c/sdk/+/480880 has been updated with the latest commits from this pull request.

@Arbaaz123676 Arbaaz123676 force-pushed the fix-macos-sigpipe-process-start branch from 1145ba9 to e77016d Compare February 16, 2026 10:22
@copybara-service

Copy link
Copy Markdown

https://dart-review.googlesource.com/c/sdk/+/480880 has been updated with the latest commits from this pull request.

1 similar comment
@copybara-service

Copy link
Copy Markdown

https://dart-review.googlesource.com/c/sdk/+/480880 has been updated with the latest commits from this pull request.

@mraleph mraleph left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A better name for the PR is: [vm] Allow to skip crash handler installation in bin::Platform::Initialize

Comment thread runtime/bin/platform.h
Comment thread runtime/bin/platform_macos.cc Outdated
}

bool Platform::Initialize() {
bool Platform::Initialize(bool install_crash_handler) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  1. We would usually write bool install_crash_hander /* = true */ to make default value obvious (otherwise reader must go to declaration to see it).

  2. You need to modify all platform specific Platform::Initialize implementations in all runtime/bin/platform_*.cc files in the same way. Otherwise the build will break.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Just to confirm before I proceed — since we changed the signature of Platform::Initialize in platform.h, do you want me to update the function signature to Initialize(bool install_crash_handler /*= true */) across all platform-specific implementations (platform_linux.cc, platform_win.cc, platform_fuchsia.cc, platform.cc) as well, without changing their logic?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not changing the logic would be inconsistent. They should all do the same thing, so they should all get the additional parameter and respect that parameter.

@Arbaaz123676 Arbaaz123676 changed the title [vm] Respect install_crash_handler in Platform::Initialize on macOS. [vm] Allow to skip crash handler installation in bin::Platform::Initialize. Feb 16, 2026
@copybara-service

Copy link
Copy Markdown

https://dart-review.googlesource.com/c/sdk/+/480880 has been updated with the latest commits from this pull request.

@Arbaaz123676 Arbaaz123676 force-pushed the fix-macos-sigpipe-process-start branch from e77016d to 5efabee Compare February 16, 2026 11:06
@copybara-service

Copy link
Copy Markdown

https://dart-review.googlesource.com/c/sdk/+/480880 has been updated with the latest commits from this pull request.

1 similar comment
@copybara-service

Copy link
Copy Markdown

https://dart-review.googlesource.com/c/sdk/+/480880 has been updated with the latest commits from this pull request.

}

bool Platform::Initialize() {
bool Platform::Initialize(bool install_crash_handler /* = true */) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be the same as Mac OS X version, but it is not updated for some reason and just ignores the parameter.

Comment thread runtime/bin/platform_win.cc Outdated

bool Platform::Initialize() {
bool Platform::Initialize(bool install_crash_handler /* = true */) {
PlatformWin::InitOnce();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

PlatformWin::InitOnce installs crash handler. So it should probably respect install_crash_handler.

@Arbaaz123676 Arbaaz123676 force-pushed the fix-macos-sigpipe-process-start branch from 5efabee to b79fda3 Compare February 16, 2026 12:00
@copybara-service

Copy link
Copy Markdown

https://dart-review.googlesource.com/c/sdk/+/480880 has been updated with the latest commits from this pull request.

1 similar comment
@copybara-service

Copy link
Copy Markdown

https://dart-review.googlesource.com/c/sdk/+/480880 has been updated with the latest commits from this pull request.

Comment thread runtime/bin/platform_win.cc Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we want to if (install_crash_handler) just this one. Not other things in this function.

@Arbaaz123676 Arbaaz123676 force-pushed the fix-macos-sigpipe-process-start branch from b79fda3 to deeed63 Compare February 17, 2026 09:56
@copybara-service

Copy link
Copy Markdown

https://dart-review.googlesource.com/c/sdk/+/480880 has been updated with the latest commits from this pull request.

1 similar comment
@copybara-service

Copy link
Copy Markdown

https://dart-review.googlesource.com/c/sdk/+/480880 has been updated with the latest commits from this pull request.

@Arbaaz123676

Copy link
Copy Markdown
Contributor Author

@mraleph, Updated macOS, Linux and Windows implementations to consistently respect "install_crash_handler". Only crash handler setup is conditional now.

Please let me know if anything else needs adjustment.

@mraleph

mraleph commented Feb 17, 2026

Copy link
Copy Markdown
Member

I have merged the CL. Thanks for the contribution. Now we need to figure what to do with Flutter embedder. It should just call dart::bin::Platform::Init(/*install_crash_handler=*/false) somewhere.

@Arbaaz123676

Copy link
Copy Markdown
Contributor Author

What if we add a call to dart::bin::Platform::Init(false) during Flutter engine VM initialization (maybe in dart_vm.cc) before Dart runtime startup, so Flutter fully owns the crash handling?

@mraleph

mraleph commented Feb 17, 2026

Copy link
Copy Markdown
Member

Yeah, something like that. You should ask Flutter engine folks what's the best place to put it in.

@Arbaaz123676

Copy link
Copy Markdown
Contributor Author

Thanks! I’m not very familiar yet with the Flutter engine workflow — should I open an issue in the Flutter engine repo about where to place the dart::bin::Platform::Init(false) call. or is there a specific place you recommend reaching out to?

@mraleph

mraleph commented Feb 17, 2026

Copy link
Copy Markdown
Member

@Arbaaz123676 you can start by asking on Flutter Discord.

@Arbaaz123676

Copy link
Copy Markdown
Contributor Author

Hello @mraleph — one of the Flutter contributors replied with:
“Flutter does not currently call dart::bin::Platform::Initialize().

Calling Platform::Initialize(false) within the DartVM constructor in https://github.com/flutter/flutter/blob/master/engine/src/flutter/runtime/dart_vm.cc seems reasonable. I can try to build a PR to do this next week.

I’m not sure whether any OS-specific Platform::Initialize implementations might introduce undesirable side effects on some target platforms (such as Android). If so, we may need to exclude it on certain platforms.”

Based on this, I’m planning to open an issue in the Flutter repository (https://github.com/flutter/flutter/issues) also with reference of the related Dart issue (#62679) as well as the PR (#62680) for context.

I would really appreciate your guidance on whether this is the right place to track it and if there’s anything specific I should consider before opening the issue. Thank you!

jason-simmons added a commit to jason-simmons/flutter that referenced this pull request Feb 20, 2026
This does platform-specific setup for Dart (such as configuring signal handlers)

Fixes flutter#182436
See dart-lang/sdk#62679
See dart-lang/sdk#62680
jason-simmons added a commit to jason-simmons/flutter that referenced this pull request Feb 23, 2026
This does platform-specific setup for Dart (such as configuring signal handlers)

Fixes flutter#182436
See dart-lang/sdk#62679
See dart-lang/sdk#62680
github-merge-queue Bot pushed a commit to flutter/flutter that referenced this pull request Feb 25, 2026
This does platform-specific setup for Dart (such as configuring signal
handlers)

Fixes #182436
See dart-lang/sdk#62679
See dart-lang/sdk#62680
ahmedsameha1 pushed a commit to ahmedsameha1/flutter that referenced this pull request Feb 27, 2026
…182689)

This does platform-specific setup for Dart (such as configuring signal
handlers)

Fixes flutter#182436
See dart-lang/sdk#62679
See dart-lang/sdk#62680
xxxOVALxxx pushed a commit to xxxOVALxxx/flutter that referenced this pull request Mar 10, 2026
…182689)

This does platform-specific setup for Dart (such as configuring signal
handlers)

Fixes flutter#182436
See dart-lang/sdk#62679
See dart-lang/sdk#62680
mboetger pushed a commit to mboetger/flutter that referenced this pull request Mar 26, 2026
…182689)

This does platform-specific setup for Dart (such as configuring signal
handlers)

Fixes flutter#182436
See dart-lang/sdk#62679
See dart-lang/sdk#62680
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

Successfully merging this pull request may close these issues.

Process.start with non-existent command delivers SIGPIPE, killing Flutter apps on macOS

2 participants