Skip to content

fix: move Release and delete out of BlockingCall callback to prevent SIGBUS on macOS#21629

Open
ludamad wants to merge 1 commit intonextfrom
fix/threaded-async-op-sigbus-v4
Open

fix: move Release and delete out of BlockingCall callback to prevent SIGBUS on macOS#21629
ludamad wants to merge 1 commit intonextfrom
fix/threaded-async-op-sigbus-v4

Conversation

@ludamad
Copy link
Copy Markdown
Collaborator

@ludamad ludamad commented Mar 16, 2026

Fixes SIGBUS crash on macOS in ThreadedAsyncOperation (#21138). Also targeting next via #21625.

Release() and delete op were inside the BlockingCall callback, which runs on the JS thread while BlockingCall is still blocked on the worker thread. Release() tears down TSFN internals (mutex/condvar) that BlockingCall needs to unwind, and delete destroys the member entirely. macOS unmaps freed pages aggressively → SIGBUS. Linux → silent use-after-free / segfault.

Fix: move both Release() and delete this to after BlockingCall returns on the worker thread.

Full post mortem with diagrams

@ludamad ludamad added the ci-barretenberg Run all barretenberg/cpp checks. label Mar 16, 2026
@ludamad ludamad force-pushed the backport-to-v4-staging branch from 9221e1a to be9b609 Compare March 17, 2026 18:16
Copy link
Copy Markdown
Contributor

@dbanks12 dbanks12 left a comment

Choose a reason for hiding this comment

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

This diff is large (needs rebase?), but the change to async_op.hpp lgtm

…SIGBUS on macOS

Release() and delete were called inside the BlockingCall callback, which runs
on the JS thread while BlockingCall is still blocked on the worker thread.
Release() drops the TSFN refcount to 0, tearing down internal state that
BlockingCall needs to unwind. delete destroys the TSFN member entirely.
Both cause use-after-free when BlockingCall returns on the worker thread.

macOS magazine malloc unmaps freed pages aggressively → SIGBUS.

Fix: move both Release() and delete to after BlockingCall returns on the
worker thread, where they can execute safely.
@ludamad ludamad force-pushed the fix/threaded-async-op-sigbus-v4 branch from bbdb7f7 to 91fab20 Compare March 17, 2026 18:57
@ludamad ludamad changed the base branch from backport-to-v4-staging to next March 17, 2026 18:57
@ludamad ludamad removed the ci-barretenberg Run all barretenberg/cpp checks. label Mar 17, 2026
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.

3 participants