Skip to content

Memory leak in Next.js SSR under bun --bun next start — JSC GC fails to reclaim heap after concurrent requests #29267

@Playys228

Description

@Playys228

What version of Bun is running?

1.3.12

What platform is your computer?

Linux 6.19.9-zen1-1-zen (Arch)

What steps can reproduce the bug?

Setup

Next.js 16.2.3 app with App Router, React 19.2.5. A Server Component fetches unique product data from a backend API on every request:

// app/products/[brandSlug]/[slug]/page.tsx
import { cache } from 'react'

const getProduct = cache(async (brandSlug: string, slug: string) => {
  const res = await fetch(`http://localhost:3001/products/${brandSlug}/${slug}`, {
    cache: 'no-store',
  })
  return res.json() // ~5-50KB per product, each URL is unique
})

export default async function ProductPage({ params }) {
  const { brandSlug, slug } = await params
  const product = await getProduct(brandSlug, slug)
  return <div>{product.title}</div>
}

Example of load script

// load-test.ts — run with: bun run load-test.ts
const products = [/* 25,000 unique {brandSlug, slug} pairs from DB */]

for (let i = 0; i < products.length; i += 100) {
  const batch = products.slice(i, i + 100)
  await Promise.all(
    batch.map(p =>
      fetch(`http://localhost:3000/products/${p.brandSlug}/${p.slug}`).then(r => r.text())
    )
  )
}

An error exists also on bun versions like 1.3.12 and 1.3.11

What is the expected behavior?

  • Application should work without memory spikes using nextjs.
  • Shouldn't crash by SIGTRAP from linux kernel.
  • Memory usage grows from 5% from machine memory to 70%.

The same application under Node.js (next start) handles the identical load test without issues:

  • Memory grows during request processing but V8 GC reclaims it between batches
  • No SIGTRAP, no ECONNRESET, all 25,000 requests complete
  • RSS stabilizes and does not grow unboundedly

What do you see instead?

Apllication crashed SIGTRAP from linux kernel.

Additional information

No response

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