Skip to content

fix: use try_init instead of init for tracing subscriber to avoid panic#8698

Closed
cal-gooo wants to merge 1 commit intorolldown:mainfrom
cal-gooo:worktree-fix-8656-tracing-panic
Closed

fix: use try_init instead of init for tracing subscriber to avoid panic#8698
cal-gooo wants to merge 1 commit intorolldown:mainfrom
cal-gooo:worktree-fix-8656-tracing-panic

Conversation

@cal-gooo
Copy link
Copy Markdown
Contributor

Summary

  • Replace .init() with .try_init() for tracing subscriber initialization in rolldown_tracing and rolldown_devtools
  • .init() calls set_global_default() which panics if a global subscriber is already set; .try_init() returns a Result instead
  • Fixes concurrent build scenarios (e.g. multiple build() calls via Promise.all) where the second initialization would panic

Closes #8656

Test plan

  • cargo check -p rolldown_tracing -p rolldown_devtools passes
  • Concurrent builds via vite-plus no longer panic with SetGlobalDefaultError

🤖 Generated with Claude Code

When running concurrent builds, `set_global_default()` (called by `.init()`)
panics if a global subscriber has already been set. Replace `.init()` with
`.try_init()` so the second call gracefully returns an error instead of
panicking.

Closes rolldown#8656

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Mar 14, 2026

Merging this PR will not alter performance

✅ 6 untouched benchmarks
⏩ 8 skipped benchmarks1


Comparing cal-gooo:worktree-fix-8656-tracing-panic (b0fc4b0) with main (e088676)2

Open in CodSpeed

Footnotes

  1. 8 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on main (68f6274) during the generation of this report, so e088676 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@hyf0 hyf0 added the ai-bot label Mar 15, 2026
@Boshen
Copy link
Copy Markdown
Member

Boshen commented Mar 21, 2026

this is not a good fix for this race condition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Panic]: failed to set global default subscriber: SetGlobalDefaultError("a global default trace dispatcher has already been set")

3 participants