Skip to content

Block profiler signals (SIGUSR2/SIGPROF) before starting Tokio runtime#107

Open
robertbuessow wants to merge 1 commit into
mainfrom
fix/profiler-signal-masking
Open

Block profiler signals (SIGUSR2/SIGPROF) before starting Tokio runtime#107
robertbuessow wants to merge 1 commit into
mainfrom
fix/profiler-signal-masking

Conversation

@robertbuessow
Copy link
Copy Markdown
Contributor

Summary

Julia's CPU profiler delivers SIGUSR2 to every adopted Julia thread to collect backtraces. Tokio worker threads become adopted Julia threads via the @ccallable preamble in notify_result_iceberg, but while they execute Rust code between Julia callbacks their Julia task context is incomplete. Receiving SIGUSR2 in that state causes UB in Julia's signal handler, manifesting as a hang when Profile.@profile is active.

Fix: call pthread_sigmask(SIG_BLOCK, {SIGUSR2, SIGPROF}, &old) on the calling thread immediately before iceberg_init_runtime. Tokio worker threads inherit the mask and are never targeted by the profiler. The original mask is restored on the calling thread via finally after init_runtime returns.

  • Linux only (@static if Sys.islinux()); the helpers are no-ops on other platforms.
  • Also blocks SIGPROF (used by older Julia / macOS profilers).
  • No changes to the Rust FFI layer.

Test plan

  • make test passes
  • Profile.@profile over an active scan no longer hangs

🤖 Generated with Claude Code

Block SIGUSR2/SIGPROF on the calling thread before starting the Tokio
runtime so worker threads inherit a mask that excludes Julia profiler
signals, preventing UB hangs when Profile.@Profile is active.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant