Skip to content

Conversation

@marxin
Copy link
Contributor

@marxin marxin commented Nov 26, 2025

Second attempt suggested by @zebreus. Tested that locally and works reliably it seems.

Fixes: #5877

Copy link
Contributor

Copilot AI left a 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 atexit handler to detect when program exit is initiated
  • Skips frame deregistration in Drop when exit has been called
  • Uses AtomicBool with SeqCst ordering to coordinate between the exit handler and Drop

💡 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.

Comment on lines 276 to 273
#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
{
compact_unwind::__unw_remove_dynamic_eh_frame_section(*registration);
self.compact_unwind_mgr.deregister();
}
Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Contributor Author

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?

@marxin
Copy link
Contributor Author

marxin commented Nov 26, 2025

Hm, it's causing a new segfault:

./run.sh: line 3: 15775 Segmentation fault      (core dumped) $WASMER -q run main.wasm --dir . -- failing_exec
Testing fork...
Testing fork ❌

@zebreus I was unable to reproduce it locally (running it 1000x). Can you check it?

@zebreus
Copy link
Contributor

zebreus commented Nov 27, 2025

I reran the CI job on this PR and it seems consistently broken. Not sure why, it seems completly unrelated to the change

@zebreus zebreus force-pushed the prevent-deregistering-on-exit-v2 branch from 5a7f39f to c48e850 Compare November 27, 2025 09:22
@zebreus
Copy link
Contributor

zebreus commented Nov 27, 2025

Rebased this PR on the latest main, maybe that fixes it

@zebreus
Copy link
Contributor

zebreus commented Nov 27, 2025

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

@marxin marxin force-pushed the prevent-deregistering-on-exit-v2 branch from 21518e1 to c48e850 Compare November 27, 2025 12:29
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.

cargo r --features=llvm -p wasmer-cli run --disable-cache cowsay aa - crashes occasionally

3 participants