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

Avoid crashes on macOS by exec(2) after daemonize #14

Merged
merged 3 commits into from
Nov 1, 2024
Merged

Conversation

sorah
Copy link
Owner

@sorah sorah commented Nov 1, 2024

We can encounter the following error if we continue without re-exec(2)-ing:

objc[11602]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.

In Mairu's case, most these crashes are triggered in a copy_certificates_from_keychain dispatch queue thread.

This is likely relevant to security-framework crate which utilise Security.framework for TLS functionality, and appears to be difficult to avoid; unforeseen risks remain ahead that could cause similar issues.

We're avoiding by re-exec(2)-ing itself to prevent the issue at all.

See also: https://www.sealiesoftware.com/blog/archive/2017/6/5/Objective-C_and_fork_in_macOS_1013.html

We can encounter the following error if we continue without
re-exec(2)-ing:

    objc[11602]: +[__NSCFConstantString initialize] may have been in
    progress in another thread when fork() was called.
    We cannot safely call it or ignore it in the fork() child process.
    Crashing instead. Set a breakpoint on objc_initializeAfterForkError
    to debug.

In Mairu's case, most these crashes are triggered in
a copy_certificates_from_keychain dispatch queue thread.

This is likely relevant to security-framework crate which utilise
Security.framework for TLS functionality, and appears to be difficult to
avoid; unforeseen risks remain ahead that could cause similar issues.

We're avoiding by re-exec(2)-ing itself to prevent the issue at all.

See also: https://www.sealiesoftware.com/blog/archive/2017/6/5/Objective-C_and_fork_in_macOS_1013.html
@sorah sorah merged commit c13e39a into main Nov 1, 2024
3 checks passed
@sorah sorah deleted the fix-macos-crash branch November 1, 2024 12:55
@sorah sorah restored the fix-macos-crash branch January 16, 2025 06:53
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.

1 participant