Skip to content

fix(rewrite): skip fork/adopt injection for detached thread spawns#113

Merged
rocketman-code merged 1 commit intomainfrom
fix/skip-detached-fork
Feb 25, 2026
Merged

fix(rewrite): skip fork/adopt injection for detached thread spawns#113
rocketman-code merged 1 commit intomainfrom
fix/skip-detached-fork

Conversation

@rocketman-code
Copy link
Owner

Summary

  • Skip fork/adopt injection for detached spawns (std::thread::spawn, rayon::spawn): they require F: 'static, and SpanContext dropping on the child thread silently loses CPU attribution data
  • Add FORK_TRIGGER_FUNCTIONS constant containing only scoped concurrency functions (scope, scope_fifo, join) that safely support fork/adopt
  • Scoped s.spawn() method calls inside scope bodies continue working via recurse_closure_body_for_spawns

Test plan

  • skips_fork_for_thread_spawn -- verifies no fork/adopt injected for std::thread::spawn
  • skips_fork_for_short_path_thread_spawn -- verifies bare spawn() also skipped
  • no_concurrency_for_thread_spawn -- verifies no concurrency reported for detached spawn
  • mixed_scope_and_thread_spawn -- verifies exactly 1 adopt (in s.spawn) when both rayon::scope and std::thread::spawn present
  • Existing scope/par_iter tests pass (no regression)
  • E2E: std::thread::spawn repro project builds and runs (was E0597/E0373 before)
  • E2E: rayon::scope repro project still builds with fork/adopt injected
  • Full test suite (157 pass), clippy clean, rustdoc clean

Closes #103

All free-function spawns (std::thread::spawn, rayon::spawn,
tokio::spawn) require F: Send + 'static. When SpanContext is moved into
such a closure it drops on the child thread, where the STACK
thread-local is empty -- silently losing CPU time attribution.

Introduce FORK_TRIGGER_FUNCTIONS (scope, scope_fifo, join) to limit
fork/adopt injection to scoped concurrency boundaries only. Detached
spawn() calls are now detected and skipped in both find_concurrency_pattern
(no fork injected) and inject_adopt_in_concurrency_closures (no adopt
injected, no recursion into closure body).

Closes #103
@rocketman-code rocketman-code merged commit 87c74b2 into main Feb 25, 2026
5 checks passed
@rocketman-code rocketman-code deleted the fix/skip-detached-fork branch February 25, 2026 10:13
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.

Bug: fork/adopt injection causes lifetime error with std::thread::spawn

1 participant