Skip to content

fix(windows): disable bmalloc/libpas linking to fix crash#28098

Open
robobun wants to merge 4 commits intomainfrom
claude/fix-windows-bmalloc-crash-28097
Open

fix(windows): disable bmalloc/libpas linking to fix crash#28098
robobun wants to merge 4 commits intomainfrom
claude/fix-windows-bmalloc-crash-28097

Conversation

@robobun
Copy link
Collaborator

@robobun robobun commented Mar 14, 2026

Summary

bmalloc/libpas causes crashes on Windows under memory pressure during garbage collection (10GB+ RSS). This was previously fixed in WebKit PR #97 (-DUSE_SYSTEM_MALLOC=ON) and Bun PR #20931 (removing bmalloc.lib from link targets), but a later WebKit update dropped the USE_SYSTEM_MALLOC=ON flag from windows-release.ps1, re-enabling bmalloc in the prebuilt binaries.

Root cause

The prebuilt WebKit for Windows (commit 00e825523d) is compiled without -DUSE_SYSTEM_MALLOC=ON, so WTF.lib and JavaScriptCore.lib contain references to bmalloc symbols. Simply removing bmalloc.lib from the Bun link step causes unresolved symbol errors (CI build #39584 failed on windows-x64-build-bun).

What this PR does

Adds TODO(#28097) comments in scripts/build/deps/webkit.ts marking where bmalloc should be excluded on Windows once the upstream fix is applied.

Required upstream fix (tracked in #28101)

The full fix requires a coordinated change:

  1. oven-sh/WebKit: Re-add -DUSE_SYSTEM_MALLOC=ON to windows-release.ps1 and publish new prebuilts
  2. oven-sh/bun: Remove bmalloc.lib from Windows link targets, exclude bmallocLib(cfg) on Windows, add CI regression guard

Related issues

🤖 Generated with Claude Code

bmalloc/libpas has a documented history of instability on Windows,
causing crashes during garbage collection under memory pressure. It was
originally disabled in PR #20931, accidentally re-enabled in PR #26381
(WebKit update), and fixed in commits 91949f7/9b87e4a3f3 — but those
fixes were never merged to main. The recent CMake-to-TypeScript build
migration also carried over the unconditional bmalloc linking.

This removes bmalloc.lib from Windows link targets in both the legacy
CMake build and the new TypeScript (ninja) build system.

Fixes #28097
Fixes #26985
Fixes #26982

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@robobun
Copy link
Collaborator Author

robobun commented Mar 14, 2026

Updated 4:51 AM PT - Mar 14th, 2026

❌ Your commit b71b6d67 has 2 failures in Build #39588 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 28098

That installs a local version of the PR into your bun-28098 executable, so you can run:

bun-28098 --bun

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 14, 2026

Walkthrough

Added inline documentation comments to WebKit dependency paths noting that bmallocLib should be excluded on Windows once prebuilts are rebuilt with -DUSE_SYSTEM_MALLOC=ON. Implementation logic remains unchanged.

Changes

Cohort / File(s) Summary
WebKit Dependency Documentation
scripts/build/deps/webkit.ts
Added 6 comment lines to both prebuilt and local WebKit dependency paths documenting planned removal of bmallocLib on Windows following prebuilt rebuilds with system malloc flag.
🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The PR description provides comprehensive context about the bmalloc crash issue, root cause analysis, and planned upstream fix, but lacks explicit sections matching the required template structure. Reorganize the description to explicitly include 'What does this PR do?' and 'How did you verify your code works?' sections as specified in the template, even if content already exists elsewhere in the description.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(windows): disable bmalloc/libpas linking to fix crash' accurately describes the main purpose of adding TODO comments for disabling bmalloc on Windows.
Linked Issues check ✅ Passed The PR adds TODO comments documenting the need to exclude bmallocLib on Windows, directly addressing the crash issues #28097, #26985, and #26982 caused by bmalloc/libpas instability.
Out of Scope Changes check ✅ Passed The changes are narrowly scoped to adding inline documentation comments in webkit.ts without modifying actual logic, staying within the PR's declared objective of adding TODOs.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scripts/build/deps/webkit.ts`:
- Around line 262-264: Add a CI regression guard that fails on Windows if
bmalloc/libpas get into the link inputs: after the libs array is computed (the
variable libs built from coreLibs(cfg), prebuiltIcuLibs(cfg), and
bmallocLib(cfg)) and likewise after the other final-link-inputs block around
lines 287-290 where link inputs are assembled, add a check when cfg.windows is
true that scans the combined input paths and throws/returns a hard failure (or
process.exit(1)) if any entry contains "bmalloc" or "libpas" (or matches
"bmalloc.lib"/"libpas" filenames); reference the symbols libs, coreLibs,
prebuiltIcuLibs, bmallocLib and the final link-input array and fail with a clear
message so CI catches any accidental reintroduction on Windows.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 3cc2fe1a-dacc-427a-b413-7f5e3bb48db6

📥 Commits

Reviewing files that changed from the base of the PR and between 1f134a1 and 01c45f8.

📒 Files selected for processing (2)
  • cmake/targets/BuildBun.cmake
  • scripts/build/deps/webkit.ts
💤 Files with no reviewable changes (1)
  • cmake/targets/BuildBun.cmake

Adds assertNoBmallocOnWindows() that throws a clear error if any
bmalloc or libpas library sneaks into the Windows link inputs. Called
in both the prebuilt and local build paths of the provides() function
so CI catches any accidental reintroduction.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Contributor

Found 8 issues this PR may fix:

  1. Bun v1.3.10 crashes with segmentation fault on Windows 10 x64 #27414 - Windows segmentation fault crash that appears to have similar memory allocation patterns
  2. Segfault (null pointer at 0x0) in long-running standalone executable on Windows after sustained memory pressure #26862 - Segfault on Windows after sustained memory pressure, directly related to bmalloc/memory allocation issues
  3. Segmentation fault after long-running session (v1.3.9-canary.51) #26984 - Segmentation fault after long-running session, likely caused by memory allocator issues
  4. Bun crashes in Claude Code cause Windows BSOD (KERNEL_SECURITY_CHECK_FAILURE) — full system reboots on Windows 11 x64 #27692 - Windows BSOD crashes that could be related to low-level memory allocation problems
  5. [Windows] N-API vtable corruption causes segfault, TUI escape, and orphaned processes in Bun v1.3.10 #27471 - Windows N-API corruption causing segfaults, potentially linked to memory management
  6. bunx crashes with "out of memory" during postinstall (Windows 11, Bun v1.2.16) #20444 - Out of memory crashes on Windows during postinstall, related to memory allocation failures
  7. Bun crashes when trying to install gemini-cli (windows bin linking assertion fail) #23414 - Windows bin linking assertion failures that could be memory allocator related
  8. Segmentation Fault in Bun v1.3.5 on Windows 10 x64 During Opencode Execution #26026 - Windows segfault during execution, matching the pattern of bmalloc-related crashes

If this is helpful, consider adding Fixes # to the PR description to auto-close the issue on merge.

🤖 Generated with Claude Code

The prebuilt WebKit for Windows is currently compiled without
-DUSE_SYSTEM_MALLOC=ON, so WTF.lib and JavaScriptCore.lib have
references to bmalloc symbols. Simply removing bmalloc.lib from the
link inputs causes unresolved symbol errors.

The proper fix requires two coordinated changes:
1. oven-sh/WebKit: Re-add -DUSE_SYSTEM_MALLOC=ON to windows-release.ps1
   (was removed after WebKit PR #97 added it, but a later update dropped it)
2. oven-sh/bun: Remove bmalloc.lib from Windows link targets

This commit adds TODO(#28097) comments marking where bmalloc should be
excluded once the prebuilts are rebuilt.

Refs #28097

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

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scripts/build/deps/webkit.ts`:
- Around line 261-265: The bmalloc/libpas allocator is still being appended
unconditionally; update the arrays that include bmallocLib(cfg) (the lines that
build const libs = [...coreLibs(cfg), ...prebuiltIcuLibs(cfg), bmallocLib(cfg)]
and the similar prebuilt/local path around the other occurrence) to exclude
bmallocLib when building for Windows by checking the cfg platform (e.g., if
(cfg.platform !== 'windows') push bmallocLib(cfg) or use a conditional spread).
Ensure both places (the prebuilt path and the local/core libs assembly where
bmallocLib(cfg) is currently added) use the same platform guard so Windows
builds do not link bmalloc/libpas.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 37fbb172-c005-46e6-90cb-b4fae5a070c0

📥 Commits

Reviewing files that changed from the base of the PR and between 523a2fd and b71b6d6.

📒 Files selected for processing (1)
  • scripts/build/deps/webkit.ts

Comment on lines +261 to 265
//
// TODO(#28097): bmalloc/libpas causes crashes on Windows under memory
// pressure. Once oven-sh/WebKit rebuilds prebuilts with
// -DUSE_SYSTEM_MALLOC=ON, exclude bmallocLib on Windows here.
const libs = [...coreLibs(cfg), ...prebuiltIcuLibs(cfg), bmallocLib(cfg)];
Copy link
Contributor

@coderabbitai coderabbitai bot Mar 14, 2026

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

TODO-only update leaves the Windows crash path unchanged.

Line 265 and Line 290 still append bmallocLib(cfg) unconditionally, so Windows continues linking bmalloc/libpas in both prebuilt and local paths. That means the allocator-crash mitigation objective is not actually implemented yet. This needs a real Windows exclusion (or the prerequisite WebKit/prebuilt allocator switch delivered in the same PR) before merge.

Also applies to: 288-290

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/build/deps/webkit.ts` around lines 261 - 265, The bmalloc/libpas
allocator is still being appended unconditionally; update the arrays that
include bmallocLib(cfg) (the lines that build const libs = [...coreLibs(cfg),
...prebuiltIcuLibs(cfg), bmallocLib(cfg)] and the similar prebuilt/local path
around the other occurrence) to exclude bmallocLib when building for Windows by
checking the cfg platform (e.g., if (cfg.platform !== 'windows') push
bmallocLib(cfg) or use a conditional spread). Ensure both places (the prebuilt
path and the local/core libs assembly where bmallocLib(cfg) is currently added)
use the same platform guard so Windows builds do not link bmalloc/libpas.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I initially made this exact change (excluding bmalloc on Windows), but CI build #39584 failed on windows-x64-build-bun with link errors.

Root cause: The prebuilt WebKit for Windows (commit 00e825523d) is compiled without -DUSE_SYSTEM_MALLOC=ON, so WTF.lib and JavaScriptCore.lib contain unresolved references to bmalloc symbols. We can't drop bmalloc.lib from the link inputs until the prebuilts are rebuilt.

The fix that worked in July 2025 (Bun PR #20931) was paired with WebKit PR #97 which added -DUSE_SYSTEM_MALLOC=ON to windows-release.ps1. A later WebKit update dropped that flag.

Tracked in #28101 — once the upstream prebuilts are rebuilt with -DUSE_SYSTEM_MALLOC=ON, a follow-up PR can:

  1. Exclude bmallocLib(cfg) on Windows (where the TODO comments are now)
  2. Remove bmalloc.lib from BuildBun.cmake
  3. Add the assertNoBmallocOnWindows CI guard

Copy link
Contributor

Choose a reason for hiding this comment

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

@robobun, understood — thanks for the detailed explanation. The link failure confirms the constraint: until WTF.lib / JavaScriptCore.lib in the Windows prebuilts are rebuilt with -DUSE_SYSTEM_MALLOC=ON, the bmalloc symbol references are baked into those archives and bmalloc.lib must stay on the link line. The TODO comments with the #28097 / #28101 backlinks are the correct interim approach here. I'll withdraw my earlier critique.


✏️ Learnings added
Learnt from: robobun
Repo: oven-sh/bun PR: 28098
File: scripts/build/deps/webkit.ts:261-265
Timestamp: 2026-03-14T09:39:04.350Z
Learning: In oven-sh/bun, the prebuilt WebKit for Windows (as of commit 00e825523d) is built WITHOUT -DUSE_SYSTEM_MALLOC=ON, so WTF.lib and JavaScriptCore.lib contain unresolved references to bmalloc symbols. Dropping bmallocLib(cfg) on Windows in scripts/build/deps/webkit.ts causes link errors until the upstream oven-sh/WebKit prebuilts are rebuilt with that flag. The two-step fix (tracked in PR `#28101`) is: (1) rebuild prebuilts with -DUSE_SYSTEM_MALLOC=ON in windows-release.ps1, then (2) exclude bmallocLib on Windows and remove bmalloc.lib from cmake/targets/BuildBun.cmake. Historical reference: this was fixed in bun PR `#20931` paired with WebKit PR `#97`, but a later WebKit update dropped the flag and PR `#26381` reintroduced unconditional bmalloc linking.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


🧠 Learnings used
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/js/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:11.466Z
Learning: Applies to src/js/{builtins,node,bun,thirdparty,internal}/**/*.{ts,js} : Use `process.platform` and `process.arch` for platform detection; these values are inlined and dead-code eliminated at build time

Learnt from: alii
Repo: oven-sh/bun PR: 26402
File: src/bundler/linker_context/generateChunksInParallel.zig:307-355
Timestamp: 2026-01-23T22:52:42.507Z
Learning: In Bun's bundler linker context (src/bundler/linker_context/*.zig), module_info operations for ESM bytecode caching use `catch continue` / `catch {}` to silently handle allocation failures because module_info is supplementary metadata, not critical to producing correct JavaScript output. Critical allocations use `bun.handleOom()` or `try`, but module_info operations (mi.str(), mi.addVar(), mi.requestModule(), mi.addImportInfoSingle(), etc.) intentionally use graceful degradation to avoid crashing builds on OOM for non-critical metadata. This pattern is used consistently across postProcessJSChunk.zig, generateChunksInParallel.zig, and related files.

Learnt from: CR
Repo: oven-sh/bun PR: 0
File: scripts/verify-baseline-static/CLAUDE.md:0-0
Timestamp: 2026-03-11T09:35:29.976Z
Learning: Applies to scripts/verify-baseline-static/**/allowlist-*-windows.txt : For Windows PDB symbol forms that fall back to linker attribution, allowlist entries using the form `<lib:NAME.lib>` to capture section-contribution data stable across link layout changes

Learnt from: RiskyMH
Repo: oven-sh/bun PR: 22606
File: src/glob/GlobWalker.zig:449-452
Timestamp: 2025-09-12T18:16:50.754Z
Learning: For Bun codebase: prefer using `std.fs.path.sep` over manual platform separator detection, and use `bun.strings.lastIndexOfChar` instead of `std.mem.lastIndexOfScalar` for string operations.

Learnt from: RiskyMH
Repo: oven-sh/bun PR: 24719
File: docs/bundler/executables.mdx:527-560
Timestamp: 2025-11-14T16:07:01.064Z
Learning: In the Bun repository, certain bundler features like compile with code splitting (--compile --splitting) are CLI-only and not supported in the Bun.build() JavaScript API. Tests for CLI-only features use backend: "cli" flag (e.g., test/bundler/bundler_compile_splitting.test.ts). The CompileBuildConfig interface correctly restricts these with splitting?: never;. When documenting CLI-only bundler features, add a note clarifying they're not available via the programmatic API.

Learnt from: taylordotfish
Repo: oven-sh/bun PR: 22227
File: src/memory.zig:60-76
Timestamp: 2025-09-02T17:41:07.869Z
Learning: In bun's memory utilities, when handling const pointers in deinit operations, prefer compile-time errors over silent skipping to avoid hard-to-find memory leaks. Users expect explicit failures rather than silent omissions in memory management.

Learnt from: CR
Repo: oven-sh/bun PR: 0
File: scripts/verify-baseline-static/CLAUDE.md:0-0
Timestamp: 2026-03-11T09:35:29.976Z
Learning: Applies to scripts/verify-baseline-static/**/{allowlist-*.txt,allowlist*.txt} : For Rust v0 mangled symbols in allowlist entries, use `<rust-hash>` in place of the crate-hash (e.g., `Cs[base62]_`) to survive toolchain bumps

Learnt from: robobun
Repo: oven-sh/bun PR: 27056
File: test/bundler/standalone.test.ts:281-324
Timestamp: 2026-02-16T04:26:34.633Z
Learning: In Bun's test files for `Bun.build()`, configuration validation errors (such as invalid targets, missing entrypoints, or incompatible option combinations) are thrown synchronously from `JSBundler.fromJS()` via `globalThis.throwInvalidArguments()` before a Promise is returned. These should be tested with `expect(() => Bun.build({...})).toThrow()`, not `await expect(...).rejects.toThrow()`. The Promise rejection pattern is only for errors that occur during the async build process itself.
<!-- </add_learning>

Learnt from: Jarred-Sumner
Repo: oven-sh/bun PR: 25429
File: src/bun.js/bindings/helpers.h:422-422
Timestamp: 2025-12-23T06:50:41.142Z
Learning: In Bun's C++ bindings (src/bun.js/bindings/helpers.h and similar files), when returning an empty JSC::Identifier and a VM is accessible, prefer using `vm.propertyNames->emptyIdentifier` over constructing with `JSC::Identifier(JSC::Identifier::EmptyIdentifierFlag::EmptyIdentifier)`. The cached identifier from the VM's property names table is more efficient and consistent with WebKit upgrade patterns.

@robobun
Copy link
Collaborator Author

robobun commented Mar 14, 2026

Why bmalloc.lib can't be removed yet

I initially removed bmalloc.lib from the Windows link targets, but CI build #39584 failed on windows-x64-build-bun (the link step) because:

The prebuilt WebKit for Windows (commit 00e825523d) is compiled without -DUSE_SYSTEM_MALLOC=ON. This means WTF.lib and JavaScriptCore.lib contain references to bmalloc symbols that must be resolved at link time.

History

  1. WebKit PR Installs for some dependencies are deferred to the end when they should be eager #97 (July 2025): Added -DUSE_SYSTEM_MALLOC=ON to windows-release.ps1
  2. Bun PR webkit: disable libpas on windows #20931 (July 2025): Removed bmalloc.lib from link targets (worked because prebuilt had USE_SYSTEM_MALLOC=ON)
  3. Bun PR Update WebKit #26381 (Jan 2026): WebKit update — the new WebKit version's windows-release.ps1 no longer has USE_SYSTEM_MALLOC=ON, re-enabling bmalloc in prebuilts

Required fix

The proper fix is a two-step coordinated change:

  1. oven-sh/WebKit: Re-add -DUSE_SYSTEM_MALLOC=ON to windows-release.ps1 and publish new prebuilts
  2. oven-sh/bun: Remove bmalloc.lib from link targets + add CI guard

This PR adds TODO comments marking where the changes should go once step 1 is complete.

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.

1 participant