Skip to content

chore(bun): bump to 1.4.1 to fix the bun:sql jsonb memory leak - #212

Merged
kernoeb merged 2 commits into
mainfrom
chore/bun-1.4.1
Sep 4, 2026
Merged

kernoeb merged 2 commits into
mainfrom
chore/bun-1.4.1

Conversation

@kernoeb

@kernoeb kernoeb commented Sep 4, 2026 •

Copy link
Copy Markdown
Owner

Bumps Bun to 1.4.1, which fixes the bun:sql jsonb memory leak that forced the revert to 1.3.14 in v3.3.6.

The leak is fixed

Verified against a real Postgres with 300 jsonb-bound queries of ~780 KB each:

Bun RSS after 300 queries growth
1.4.0 128 MB +54 MB, still climbing
1.4.1 33 MB −0.6 MB, flat

The fix is oven-sh/bun#40238 (bc713f9543), confirmed an ancestor of bun-v1.4.1. Note that #32293 (118673413c), the first PR linked on #40102, was closed unmerged and is not the fix.

Why the build config changed

Bun 1.4.1 ships a bundler regression. It mis-renames identifiers when bundling Elysia and emits invalid JS, so the compiled server fails to start:

SyntaxError: Cannot declare a var variable that shadows a let/const/class variable: 'Check2'.

Elysia's dist/schema.mjs holds a block-scoped let Check2 = function… next to var Check = Check2, and TypeBox declares a top-level Check. Bun renames Elysia's var Check to Check2 to resolve that collision, without accounting for the let Check2 already in scope. Both packages ship valid code; the invalid line only exists once Bun combines them.

Reported as oven-sh/bun#41351. Confirmed upstream, fix open at #41354.

The workaround is minify.identifiers: true, endorsed by Jarred on that issue: the identifier minifier uses a different renamer that is not affected. Affected range is elysia >= 1.4.28, confirmed by sweeping 1.4.25 to 1.4.30.

Minified names alone would make stack traces hard to read, so this also adds sourcemap: 'inline'. Traces keep the real source file and line, which is more useful than the bundled offsets they carried before:

before:  at refreshPlanningsForJob (/$bunfs/root/server:2:46)
after:   at e (jobs/index.ts:253:11)

The sourcemap costs what the minification saves, so the binary stays at 63.5 MB.

Changes

  • .bun-version: 1.3.14 → 1.4.1
  • bun-types catalog entry: 1.3.14 → 1.4.1
  • BUN_VERSION defaults in docker-compose.test.yml and docker-compose.test-auth.yml
  • bun.lock regenerated with the pinned Bun
  • apps/api/scripts/build.ts: minify identifiers, add an inline sourcemap

Tests

Lint, typecheck, 148 unit tests, docker:build, 16 integration tests and 14 auth integration tests all pass on 1.4.1. The integration tests are the ones that matter here, because only they boot the compiled binary.

Follow-up

None needed for the build config. Bun 1.4.2 will fix the renamer bug, but minifying identifiers stays on: it shrinks the binary, and with the inline sourcemap the stack traces are better than they were before.

🤖 Generated with Claude Code

Bun 1.4.1 ships the fix for the bun:sql jsonb native memory leak that
forced the revert to 1.3.14 in v3.3.6 (oven-sh/bun#40102, fixed by
oven-sh/bun#40238).

Verified against a real Postgres with 300 jsonb-bound queries of ~780 KB:
1.4.0 grows 33 -> 128 MB and keeps climbing, 1.4.1 stays flat.

DO NOT MERGE yet: 1.4.1 has a bundler regression that makes the compiled
server fail to boot with

  SyntaxError: Cannot declare a var variable that shadows a let/const/class
  variable: 'Check2'.

The bundler emits `var Check2 = Check2` beside a `let Check2` in the same
scope. Waiting for 1.4.2.
@kernoeb kernoeb changed the title chore(bun): bump to 1.4.1 — blocked by a 1.4.1 bundler regression chore(bun): bump to 1.4.1 to fix the bun:sql jsonb memory leak Sep 4, 2026
Minifying identifiers shrinks the compiled server and sidesteps a Bun
1.4.1 renamer bug that emits invalid JS for Elysia, so the binary failed
to start with

  SyntaxError: Cannot declare a var variable that shadows a let/const/class
  variable: 'Check2'.

Upstream confirmed this approach in oven-sh/bun#41351.

Minified names alone would leave stack traces hard to read, so add an
inline sourcemap. Traces keep the real source file and line, which is more
useful than the bundled offsets they carried before. The sourcemap costs
what the minification saves, so the binary stays at 63.5 MB.

Verified with 16 integration and 14 auth integration tests on Bun 1.4.1.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@kernoeb
kernoeb marked this pull request as ready for review September 4, 2026 10:04
@kernoeb
kernoeb enabled auto-merge (squash) September 4, 2026 10:04
@kernoeb
kernoeb merged commit 6573c6b into main Sep 4, 2026
10 checks passed
@kernoeb
kernoeb deleted the chore/bun-1.4.1 branch September 12, 2026 16:52
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