Skip to content

Segfault in the YAML parser #28917

Open
Open

Description

@illright

How can we reproduce the crash?

Same as #26088:

To reproduce the crash, checkout the repository (https://github.com/illright/ibood-archive), then set up a local archive branch to track the remote branch:

git checkout archive
git checkout main --force  # force might be needed on MacOS due to case-insensitive FS
git checkout 8c27dbd160a4fb1fe38673299ffd3e470c4088fe

Then cd into ./ui and run bunx --bun astro build

Relevant log output

============================================================
Bun v1.3.11 (af24e281) macOS Silicon
macOS v26.4
CPU: fp aes crc32 atomics
Args: "node" "/Users/illright/work/ibood-archive/node_modules/.bin/astro" "build"
Features: Bun.stderr(2) Bun.stdin(2) Bun.stdout(2) fetch(2) jsc spawn(3) transpiler_cache(2) tsconfig(2) process_dlopen(3) 
Builtins: "bun:main" "node:assert" "node:async_hooks" "node:buffer" "node:child_process" "node:crypto" "node:dns" "node:events" "node:fs" "node:fs/promises" "node:http" "node:https" "node:module" "node:net" "node:os" "node:path" "node:path/posix" "node:perf_hooks" "node:process" "node:querystring" "node:readline" "node:stream" "node:tls" "node:tty" "node:url" "node:util" "node:zlib" "node:worker_threads" "ws" "node:v8" "node:http2" 
Elapsed: 50261ms | User: 47835ms | Sys: 6124ms
RSS: 4.91GB | Peak: 4.91GB | Commit: 2.47GB | Faults: 5895 | Machine: 17.18GB

panic(main thread): Segmentation fault at address 0x16A93BFF0
oh no: Bun has crashed. This indicates a bug in Bun, not your code.

To send a redacted crash report to Bun's team,
please file a GitHub issue using the link below:

 https://bun.report/1.3.11/Mn1af24e28ijEugogC____________________A2Cg//uyqD

Stack Trace (bun.report)

Bun v1.3.11 (af24e28) on macos aarch64 [AutoCommand]

Segmentation fault at address 0x000000C8

  • 20 unknown/js code

Features: transpiler_cache, tsconfig, process_dlopen, exited, Bun.stderr, Bun.stdin, Bun.stdout, dotenv, http_server, jsc

Activity

  1. illright commented on Apr 6, 2026

    @illright
    Author

    Actually, I'm not sure if it's the YAML parser this time — I opened this issue to bring attention to an earlier comment of mine that slipped through the cracks, but this actually looks like a different segfault

  2. github-actions commented on Apr 6, 2026

    @github-actions
    Contributor

    Found 1 possible duplicate issue:

    1. Segfault after generating 20k pages with Astro #26088

    This issue will be automatically closed as a duplicate in 3 days.

    • If your issue is a duplicate, please close it and 👍 the existing issue instead
    • To prevent auto-closure, add a comment or 👎 this comment

    🤖 Generated with Claude Code

  3. robobun commented on Apr 6, 2026

    @robobun
    Collaborator

    Reproduced at 8c27dbd160a4fb1fe38673299ffd3e470c4088fe — but this turns out to be an upstream bug in the es-git native module, not in Bun. Node.js v24.3.0 crashes identically.

    What's actually happening

    The crash is a stack overflow during process teardown, inside es-git's napi finalizer — not in Bun.YAML.parse. (That lines up with the fault address 0x16A93BFF0, which is the darwin-arm64 main-thread stack guard page, and with the crash happening after "Complete!".)

    Your ui/src/content.config.ts does this for every file in every commit on the archive branch:

    commit.tree().walk("PreOrder", (entry) => {
      // ...
      entry.toObject(repo).peelToBlob().content()

    With ~180 commits × ~5,000 files that creates ~830k Blob objects. When the process exits and the runtime calls es-git's napi finalizer once, the Rust drop implementation for these objects recurses ~260,000 frames deep and overflows the 8 MB main-thread stack.

    Bun.YAML.parse is fine

    Stress-tested the real product YAML standalone — 800k parses, RSS flat at ~150 MB, no crash.

    Minimal reproduction — no Astro, no YAML, no Bun APIs

    // esgit-min.mjs
    import { openRepository } from "es-git";
    const repo = await openRepository("/path/to/ibood-archive");
    const head = repo.getBranch("archive", "Local").referenceTarget();
    let n = 0;
    for (const sha of repo.revwalk().push(head)) {
      const commit = repo.getCommit(sha);
      commit.tree().walk("PreOrder", (entry) => {
        if (entry.type() === "Blob") {
          entry.toObject(repo).peelToBlob().content();
          n++;
        }
        return 0;
      });
    }
    console.error("DONE walked", n);
    $ bun ./esgit-min.mjs
    DONE walked 831595
    Segmentation fault (core dumped)      # exit 139
    
    $ node --version
    v24.3.0
    $ node ./esgit-min.mjs
    DONE walked 831595
    Segmentation fault (core dumped)      # exit 139

    gdb backtrace (same shape in both runtimes)

    Bun — 256k recursive frames inside es-git.linux-x64-gnu.node
    #0      _int_free_create_chunk                                  glibc
    #4      __libc_free                                              glibc
    #5      git_odb_object.free ()                                   es-git.linux-x64-gnu.node
    #6      git_blob.free ()                                         es-git.linux-x64-gnu.node
    #7      core::ops::function::FnOnce::call_once{{vtable.shim}}   es-git.linux-x64-gnu.node
    #8      core::ops::function::FnOnce::call_once{{vtable.shim}}   es-git.linux-x64-gnu.node
    …       (same frame repeated ~256,000 times)
    #256062 core::ops::function::FnOnce::call_once{{vtable.shim}}   es-git.linux-x64-gnu.node
    #256063 napi::bindgen_runtime::raw_finalize_unchecked ()         es-git.linux-x64-gnu.node  ← napi-rs entry
    #256064 …                                                        bun (napi finalize trampoline)
    
    Node.js v24.3.0 — identical
    #0      _int_free_create_chunk                                  glibc
    #5      git_odb_object.free ()                                   es-git.linux-x64-gnu.node
    #6      git_blob.free ()                                         es-git.linux-x64-gnu.node
    #7      core::ops::function::FnOnce::call_once{{vtable.shim}}   es-git.linux-x64-gnu.node
    …       (same frame repeated ~261,900 times)
    #261918 core::ops::function::FnOnce::call_once{{vtable.shim}}   es-git.linux-x64-gnu.node
    #261919 napi::bindgen_runtime::raw_finalize_unchecked ()         es-git.linux-x64-gnu.node  ← napi-rs entry
    #261920 node_napi_env__::CallFinalizer<true>(…)                  node
    #261921 v8impl::Reference::Finalize()                            node
    #261926 node::Environment::CleanupHandles()                      node
    #261927 node::Environment::RunCleanup()                          node
    #261928 node::FreeEnvironment(node::Environment*)                node
    #261929 node::NodeMainInstance::Run()                            node
    #261933 _start
    

    Bun/Node call the napi finalizer once; everything above that is the .node library shipped by es-git@0.4.0 recursing into itself via napi-rs SharedReference drop closures.

    Workaround

    Break out of the synchronous tree().walk() periodically so GC can run finalizers before hundreds of thousands pile up — e.g. collect entry ids inside the walk and read blob contents in an async loop with an occasional await 0, or run Bun.gc(true) / global.gc() between commits. Alternatively read file contents via a path that doesn't create a SharedReference per blob.

    Upstream

    This should be filed against https://github.com/toss/es-git (and/or napi-rs — the recursive FnOnce drop chain is a napi-rs SharedReference pattern). Closing here since there's nothing to change on the Bun side.

  4. illright commented on Apr 6, 2026

    @illright
    Author

    Indeed, I added some commits temporarily to move away from Bun's YAML implementation, it is still available in commit 8c27dbd160a4fb1fe38673299ffd3e470c4088fe (updated the repro instructions)

  5. Jarred-Sumner commented on Apr 11, 2026

    @Jarred-Sumner
    Collaborator

    @robobun try with 8c27dbd160a4fb1fe38673299ffd3e470c4088fe

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions