#41655·bun

napi Finalizer::run SIGSEGV under --isolate is libsql's double sqlite3_close_v2 (tursodatabase/libsql#2251), exposed since 1.4.1

Author: rchasmanCreated Sep 6, 2026Updated Sep 28, 2026
Labelsnapicrash

What version of Bun is running?

1.4.2 (744846f84) and 1.4.1 (4661e494f), macOS 15.5, arm64, 16 cores

What steps can reproduce the bug?

This is the crash from #41055, which was closed on 1 Sep 2026 as fixed by #39848. The fix shipped in 1.4.1. Against the same suite (414 files then, 457 now, @libsql/[email protected] / [email protected], file-backed SQLite) it did not remove the crash, and it made the serial case crash too.

rtk err bun test --isolate --bail --timeout 30000

We cannot share the suite. Happy to run an instrumented build or a canary against it.

What is the expected behavior?

The suite completes. On 1.4.0 it does when run serially: 2 of 2 runs, 4852 pass, 0 fail, 501s and 493s.

What do you see instead?

Same machine, same commit, same command unless noted. Every crash decodes to the same frame, <bun_runtime::napi::napi_body::Finalizer>::run (napi_body.rs:2396) via run_on_js_thread, a different test file each time, heap fault addresses.

Bun --parallel=4 --parallel=2 serial
1.4.0 crashes (see #41055) 2 of 4 crashed (see #41055) 0 of 2 crashed
1.4.1 not run not run 2 of 2 crashed (68s, 165s)
1.4.2 3 of 3 crashed (17s, 48s, 8s) 4 of 4 crashed (191s, 457s, 24s, 47s) 2 of 2 crashed (34s, 69s)

So on 1.4.0 the crash needs --parallel, as triaged in #41055. On 1.4.1 and 1.4.2 it no longer does.

Crash reports:

Sample panic, 1.4.2 serial, mid-suite (the run had ~34s of green output before it):

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

Related: #41055 (original report and triage), #39848 (the fix). #41357 looks like a different crash (bun_test_then_or_catch, fault address 0x30).

Update: the same crash on Linux arm64 CI, 1.4.0, --parallel=2, always the same file

Our GitHub Actions runs of the same suite on Bun 1.4.0 hit it too, so it is not macOS-specific. Runner: ubuntu26-arm64/20260831.111 (Ubuntu 26.04, Linux kernel 7.0.0, glibc 2.43, arm64). Command:

rtk err bun test --isolate --parallel=2 --bail --timeout 60000

Of the last 20 runs on our default branch (4 cancelled as superseded), 6 of the 16 that completed crashed. Every crash is the same file and the same address, unlike the heap addresses on macOS:

Bun v1.4.0 (34cbb9a40) Linux arm64
Linux Kernel v7.0.0 | glibc v2.43
Args: "bun" "test" "--test-worker" "--isolate" "--timeout=60000" "--max-concurrency=20" ...
panic(main thread): Segmentation fault at address 0x20
✗ src/tools/manage-memory-tool.test.ts (worker crashed: SIGSEGV)
✗ tests/get-crm-within-filter.test.ts (aborted: sibling worker panicked)

https://bun.report/1.4.0/Lt134cbb9agnEqkggC2ts9sEuv+kjC+vxj0B2wukwBmppkwBu6u90B2mxl9C+2r60BmwqzsBuj9ysBu1vysB2x3I__A2AgC

The crashing file (manage-memory-tool.test.ts) creates a fresh file-backed libsql database in beforeEach for each of its 6 tests and never closes them explicitly, so 6 connections in one worker are left to the finalizer. Many files in the suite do the same, but this one crashes every time, so the count alone does not explain it. A rerun of the failed job alone passes every time. The coverage job in the same workflow runs the same suite without --parallel and did not crash in any of those 20 runs, matching the 1.4.0 serial result above.

Update 2: closing every libsql handle before the worker exits removes the crash on 1.4.0

Same CI suite and runner as above (Bun 1.4.0, Linux arm64, bun test --isolate --parallel=2, ~460 files). Before: 9 of 36 Unit and Integration jobs over two days died with Segmentation fault at address 0x20, always in the same file. That file created a @libsql/client database per test in beforeEach and never closed it, and most of the suite did the same.

We changed one helper so every test database is closed (client.close()) in a preload afterAll before the worker exits, and reran the same commands on the same runner 10 times: 20 of 20 jobs clean, no SIGSEGV. Nothing else changed (zero-config-crm/crm-agent#1037). At the old rate the chance of 20 clean jobs by luck is about 0.4%.

So on 1.4.0 the crash needs a libsql client handle that is still open when the worker tears down, and closing handles before exit is a complete workaround there. It is still a Bun bug: the finalizer must not touch freed memory whether or not user code closed the handle, and 1.4.1 and 1.4.2 crash serially on the unmodified suite. Happy to run a candidate build against the unmodified suite.