Skip to content

Fix intermittent SIGSEGV (exit 139) of bb after successful build - #95

Open
Bobris wants to merge 1 commit into
masterfrom
fix/bb-exit-segfault
Open

Bobris wants to merge 1 commit into
masterfrom
fix/bb-exit-segfault

Conversation

@Bobris

@Bobris Bobris commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Problem

BbCliE2ETests.BuildCommandsWorkForProjectUsingBobrilG11n failed now and then with Command failed with exit code 139 (for example in run 43428941512, attempt 1, on both ubuntu and macos). Each time the bb output ended with "Build done ... with no errors".

Cause

I reproduced it locally on macOS arm64 by looping bb build -f 1 / bb build on the fixture with all CPUs busy: 1 crash in 120 runs. The macOS crash report shows the main thread in exit() and a .NET TP Worker faulting inside ClearScriptV8.osx-arm64.dylib, in V8 heap code (pooled pages).

  1. _compilerPool.FreeMemory().GetAwaiter() starts FreeMemory and never waits for it. FreeMemory resumes on a thread-pool thread as soon as the background type check returns its compiler, then disposes the V8 engines while Main is returning.
  2. Waiting for FreeMemory alone still crashed (1 in 300 runs). ClearScript keeps running V8 background tasks on the .NET thread pool after the engines are disposed, and exit() runs the native C++ static destructors underneath them.

Fix

  • RunBuild and RunTest wait for FreeMemory before they return.
  • The type checker is always returned to the pool (finally), so waiting for FreeMemory cannot hang.
  • The CssProcessor that NjsastBundleBundler creates is now disposed.
  • On non-Windows, bb registers a final ProcessExit handler that flushes the console and calls libc _exit(Environment.ExitCode). The other ProcessExit handlers (browser and watch process cleanup) were registered earlier, so they still run.

Verification

  • Same stress loop with the fix: 400 of 400 runs exit 0. No new crash reports.
  • Exit codes are unchanged: 0 on success, 1 on a type error. Output redirected to a file is complete.
  • dotnet test bbcore.sln passes locally. Bbcore.Lib builds.

🤖 Generated with Claude Code

The pooled V8 engines were disposed by an unawaited FreeMemory task on a
thread pool thread while Main was returning. Even after engine disposal,
ClearScript runs V8 background tasks (pooled page release) on the .NET
thread pool, and exit() runs ClearScriptV8 native static destructors under
them.

- Await FreeMemory before RunBuild/RunTest return
- Always release the type checker, so waiting for FreeMemory cannot hang
- Dispose the CssProcessor created by NjsastBundleBundler
- On Unix, end bb with _exit from the last ProcessExit handler

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant