Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions test/js/web/fetch/fetch-leak.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,10 @@
kind,
async () => {
const script = `
const payload = Buffer.alloc(128 * 1024, 0x61); // 128 KiB of 'a'
// 16 KiB bodies: cycle() keeps 512 alive at once and gc() may not have returned that
// memory to the OS by the time rss() is sampled, so one cycle's live set (8 MiB here)
// is the noise floor of this measurement and must stay far below the threshold.
const payload = Buffer.alloc(16 * 1024, 0x61); // 16 KiB of 'a'
const str = payload.toString("latin1");
const sharedBlob = new Blob([payload]);
const rss = process.platform === "darwin" && typeof Bun.unsafe.memoryFootprint === "function" ? Bun.unsafe.memoryFootprint : process.memoryUsage.rss;
Expand Down Expand Up @@ -705,11 +708,11 @@

const deltaMB = (final - baseline) / 1024 / 1024;
console.log(JSON.stringify({ kind: "${kind}", baselineMB: (baseline / 1024 / 1024) | 0, finalMB: (final / 1024 / 1024) | 0, deltaMB: Math.round(deltaMB) }));
// 32 cycles * 512 Requests * 128 KiB = 2 GiB through the pool. If deinit() is
// skipped for any heap-backed variant, RSS climbs by ~2 GiB; with the
// 32 cycles * 512 Requests * 16 KiB = 256 MiB through the pool. If deinit() is
// skipped for any heap-backed variant, RSS climbs by ~256 MiB; with the
// Zig semantics it stays flat. 64 MiB is well above GC/allocator noise.
// ASAN's quarantine retains freed allocations so widen the threshold there.
if (deltaMB > ${isASAN ? 320 : 64}) {

Check failure on line 715 in test/js/web/fetch/fetch-leak.test.ts

View check run for this annotation

Claude / Claude Code Review

ASAN threshold now exceeds the leak signal after body size reduction

The ASAN threshold here is still 320 MiB, but shrinking the body to 16 KiB dropped the guarded leak signal to ~256 MiB (per the updated comment two lines up) — so under `bun-asan` a real "deinit() skipped" regression would now pass this check. Either scale the ASAN bound down alongside the body size, or cap `quarantine_size_mb` in the child's `ASAN_OPTIONS` (as the neighboring tests in this file do) so a tighter bound holds.
Comment thread
robobun marked this conversation as resolved.
Outdated
throw new Error("Request body (${kind}) leaked " + Math.round(deltaMB) + " MB over 32 cycles of 512 Requests");
}
`;
Expand Down Expand Up @@ -742,9 +745,12 @@
env: {
...bunEnv,
SERVER_URL: server.url.href,
// ASAN's quarantine retains freed allocations so RSS stays elevated
// under bun-asan; the fixture only allows MAX_MEMORY_INCREASE MiB.
MAX_MEMORY_INCREASE: isASAN ? "64" : "5", // in MB
// The regression this guards retained the 128 KiB body per request, i.e.
// ~32 MiB over the 250 sampled iterations; RSS of a non-leaking run still
// drifts by several MiB over that window (allocator high-water, lazily
// freed pages), so the allowance sits between the two. ASAN's quarantine
// retains freed allocations so RSS stays elevated under bun-asan.
MAX_MEMORY_INCREASE: isASAN ? "64" : "16", // in MB
// The fixture asserts RSS stabilizes after iteration 250, but with the
// default 256 MB quarantine the freed 128 KB bodies are never reused and
// RSS keeps climbing through all 500 iterations (~97 MB past the sample
Comment thread
robobun marked this conversation as resolved.
Expand Down