-
Notifications
You must be signed in to change notification settings - Fork 922
Prevent crashes during exit due to deregistering frames on exit (v2) #5912
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
base: main
Are you sure you want to change the base?
Conversation
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.
Pull request overview
This PR prevents crashes during program exit by skipping unwind frame deregistration when exit() has been called. The fix uses an atexit handler to track when the program is exiting and early-returns from UnwindRegistry::Drop to avoid race conditions with internal unwinder state during shutdown.
Key changes:
- Adds an
atexithandler to detect when program exit is initiated - Skips frame deregistration in
Dropwhen exit has been called - Uses
AtomicBoolwithSeqCstordering to coordinate between the exit handler andDrop
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
| #[cfg(all(target_os = "macos", target_arch = "aarch64"))] | ||
| { | ||
| compact_unwind::__unw_remove_dynamic_eh_frame_section(*registration); | ||
| self.compact_unwind_mgr.deregister(); | ||
| } |
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.
I am pretty sure this is dead code, as we never make push anything into self.registrations when we are on macos aarch64
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.
@Syrus I think the correct fix would be to move the call to self.compact_unwind_mgr.deregister(); outside of the loop (potentially also add the registrations to self.registrations on macOS aarch64). However, I can't really test this as I don't have a Mac.
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.
Fair point. I would like to handle this in a separate PR as it's pretty unrelated to it.
@zebreus Does it work for you?
|
Hm, it's causing a new segfault: @zebreus I was unable to reproduce it locally (running it 1000x). Can you check it? |
|
I reran the CI job on this PR and it seems consistently broken. Not sure why, it seems completly unrelated to the change |
Fixes: #5877 Co-Authored-By: Zebreus <[email protected]>
Co-authored-by: Copilot <[email protected]>
5a7f39f to
c48e850
Compare
|
Rebased this PR on the latest main, maybe that fixes it |
|
I pushed an extra commit that reverts all changes to check if that makes CI pass to be sure that the changes actually cause the crash |
21518e1 to
c48e850
Compare
Second attempt suggested by @zebreus. Tested that locally and works reliably it seems.
Fixes: #5877