next-leak 0.11.0 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -29,13 +29,15 @@ next-leak found the growth, the retaining object and the chain that holds it —
29
29
  without being told what to look for. Next.js 16.3.0 has since fixed it.
30
30
 
31
31
  **Verified against real Next.js issues**, not synthetic fixtures. Issue states
32
- checked 2026-08-27:
32
+ checked 2026-09-05:
33
33
 
34
34
  | Issue | What it is | Measured | State today |
35
35
  |---|---|---|---|
36
- | [#97938](https://github.com/vercel/next.js/issues/97938) | `cacheComponents`: composite abort signal never released | +705 KB per request on 16.3.3, flat on 16.2.6 | **open** |
36
+ | [#97776](https://github.com/vercel/next.js/issues/97776) | `use cache`: `AbortSignal.any` composites never released (canonical issue; #97938 and #97464 are duplicates) | +705 KB per request on 16.3.3, flat on 16.2.6 (the #97938 run) | **open** — fix [#97476](https://github.com/vercel/next.js/pull/97476) merged Aug 19, in no stable release as of 16.3.4 |
37
+ | [#97938](https://github.com/vercel/next.js/issues/97938) | `cacheComponents`: composite abort signal never released | +705 KB per request on 16.3.3, flat on 16.2.6 | closed Aug 31 as a duplicate of #97776; fix in no stable release |
37
38
  | [#96533](https://github.com/vercel/next.js/issues/96533) | ISR revalidation holds RSC buffers between collections | 4–5 MB of `arrayBuffers` held vs 0.32 MB retained | **open** |
38
- | [#97464](https://github.com/vercel/next.js/issues/97464) | Static-gen worker retains per prerendered page | OOM after 1617 and 1525 of 2504 pages on 16.3.3; 16.2.12 finishes at 0.05 MB/page | **open** |
39
+ | [#97464](https://github.com/vercel/next.js/issues/97464) | Static-gen worker retains per prerendered page | OOM after 1617 and 1525 of 2504 pages on 16.3.3; 16.2.12 finishes at 0.05 MB/page | closed Aug 31 as a duplicate of #97776; fix in no stable release |
40
+ | [#97802](https://github.com/vercel/next.js/issues/97802) | Turbopack compilation saturates the container before rendering anything | Reporter's reproduction in a 2 CPU / 4 GB container: 16.2.12 peaks ~2 GB and finishes; 16.3.0 pins 4 GB and stalls | **open** — bisected to 16.3.0; no fix known |
39
41
  | [#92287](https://github.com/vercel/next.js/issues/92287) | Cache Components: unbounded `arrayBuffers` under load | 37.5 MB of arrayBuffers held between collections, 37x what it retains (16.3.1) | **open** |
40
42
  | [#84884](https://github.com/vercel/next.js/issues/84884) | axios + `AbortSignal` in middleware | 32.8 → 369.9 MB | **open** |
41
43
  | [#89091](https://github.com/vercel/next.js/issues/89091) | zlib retention on mid-stream aborts | +42.5 MB/1000 aborted req on 16.1.5; **+0.03 on 16.3.1** | closed |
@@ -121,6 +123,7 @@ Every report prints the gate it used.
121
123
  | `--idle <seconds>` | 30 | **Maximum** wait before each sample; the run continues as soon as the heap settles |
122
124
  | `--warmup <n>` | 200 | Requests before the baseline snapshot. Lower it on apps that cache per request: warm-up fills those caches and the baseline then measures the warm-up, not the app. The run says so when it happens |
123
125
  | `--max-old-space <mb>` | 512 | Heap cap of each measured process. Raise it for apps whose legitimate working set is larger, or they die under measurement |
126
+ | `--ready-timeout <seconds>` | 60 | How long each measured process gets to start listening. Raise it for apps that boot slowly. A process that never listens reports whatever it wrote to stderr while trying |
124
127
  | `--quick` | off | Fast preset (2000 requests × 4 cycles, 8s idle) — the exact profile the real-app validation ran with. Same cycle count as the default; what it trades away is traffic per cycle, so it sits on the noise floor and is less sensitive to slow leaks. Explicit flags override it |
125
128
  | `--no-resolve` | off | Skip the second pass on inconclusive routes |
126
129
  | `--self-check` | off | Measure a planted leak first to prove the harness works here. Costs one route's worth of time; a run that cannot detect 8 KB per request produces verdicts worth nothing |
@@ -407,6 +410,17 @@ through the build's source maps.
407
410
 
408
411
 
409
412
  - **Supported (default command):** App Router · `output: "standalone"` · Node ≥ 22 · Linux/macOS. Pages Router, non-standalone, and Windows are rejected with a clear message.
413
+ - **Monorepos work unchanged.** A workspace build does not put `server.js` at
414
+ the root of `.next/standalone`: Next keeps the app's path relative to the
415
+ workspace root, so an app in `client/` ships its server at
416
+ `.next/standalone/client/server.js` with `node_modules` hoisted above it.
417
+ Point the tool at the app directory as usual — it looks there too. Do not
418
+ flatten that tree by hand: on a pnpm workspace the moved `server.js` cannot
419
+ resolve `next` any more, because what sits in `standalone/<app>/node_modules`
420
+ are relative symlinks into `../../node_modules/.pnpm/`, and a level up they
421
+ point outside the tree. An npm workspace survives the move — it puts no
422
+ `node_modules` beside the app at all — which is why the same build can serve
423
+ by hand and still be unmeasurable.
410
424
  - **Sample values can vary per request.** `"slug": "post-{n}"` gives every
411
425
  request its own URL — the shape of bot traffic and of a cache that never
412
426
  repeats a key. `"slug": "post-{n%200}"` cycles through exactly 200 distinct
@@ -92698,6 +92698,26 @@ async function readManifest(file, parse2) {
92698
92698
  );
92699
92699
  }
92700
92700
  }
92701
+ async function findStandaloneServer(appDir, standaloneDir) {
92702
+ const atRoot = path2.join(standaloneDir, "server.js");
92703
+ if (await exists(atRoot)) {
92704
+ return atRoot;
92705
+ }
92706
+ let current = path2.resolve(appDir);
92707
+ let suffix = "";
92708
+ for (; ; ) {
92709
+ const parent = path2.dirname(current);
92710
+ if (parent === current) {
92711
+ return void 0;
92712
+ }
92713
+ suffix = suffix === "" ? path2.basename(current) : path2.join(path2.basename(current), suffix);
92714
+ const candidate = path2.join(standaloneDir, suffix, "server.js");
92715
+ if (await exists(candidate)) {
92716
+ return candidate;
92717
+ }
92718
+ current = parent;
92719
+ }
92720
+ }
92701
92721
  async function validateTarget(appDir) {
92702
92722
  const nextDir = path2.resolve(appDir, ".next");
92703
92723
  if (!await exists(nextDir)) {
@@ -92706,11 +92726,11 @@ async function validateTarget(appDir) {
92706
92726
  `No .next directory in ${appDir}. Run "next build" first.`
92707
92727
  );
92708
92728
  }
92709
- const standaloneServer = path2.join(nextDir, "standalone", "server.js");
92710
- if (!await exists(standaloneServer)) {
92729
+ const standaloneServer = await findStandaloneServer(appDir, path2.join(nextDir, "standalone"));
92730
+ if (standaloneServer === void 0) {
92711
92731
  throw new TargetError(
92712
92732
  "NO_STANDALONE",
92713
- `No ${standaloneServer}.
92733
+ `No ${path2.join(nextDir, "standalone", "server.js")}.
92714
92734
  next-leak measures the standalone server bundle. Enable it once in next.config:
92715
92735
 
92716
92736
  const nextConfig = {
@@ -92754,6 +92774,7 @@ import { pathToFileURL } from "url";
92754
92774
  import { z as z3 } from "zod";
92755
92775
  var controlFileSchema = z3.object({ port: z3.number(), pid: z3.number() });
92756
92776
  var DEFAULT_MAX_OLD_SPACE_MB = 512;
92777
+ var DEFAULT_READY_TIMEOUT_MS = 6e4;
92757
92778
  var LaunchError = class extends Error {
92758
92779
  constructor(message) {
92759
92780
  super(message);
@@ -92794,8 +92815,16 @@ function explainRuntimeFailure(stderr, maxOldSpaceMb) {
92794
92815
  }
92795
92816
  return `the measured process exited mid-run. ${explainStartupFailure(stderr)}`;
92796
92817
  }
92818
+ function appNeverListened(hostname, port, budgetMs, stderr) {
92819
+ const head = `app on ${hostname}:${port} \u2014 the process started and answered on its control channel, but never listened within ${Math.round(budgetMs / 1e3)}s`;
92820
+ if (stderr.trim() !== "") {
92821
+ return `${head}. It wrote this while starting:
92822
+ ${stderr.trim()}`;
92823
+ }
92824
+ return `${head}, and wrote nothing to stderr. An app that boots slower than that needs a larger budget: --ready-timeout <seconds>. Otherwise it is hanging during startup \u2014 starting the same server.js by hand, with PORT set, hangs the same way and can be interrupted to see where`;
92825
+ }
92797
92826
  var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
92798
- async function pollUntil(deadline, what, probe, failed) {
92827
+ async function pollUntil(deadline, describe, probe, failed) {
92799
92828
  for (; ; ) {
92800
92829
  const failure = failed();
92801
92830
  if (failure !== void 0) {
@@ -92806,14 +92835,14 @@ async function pollUntil(deadline, what, probe, failed) {
92806
92835
  return result;
92807
92836
  }
92808
92837
  if (Date.now() > deadline) {
92809
- throw new LaunchError(`timed out waiting for ${what}`);
92838
+ throw new LaunchError(`timed out waiting for ${describe()}`);
92810
92839
  }
92811
92840
  await sleep(100);
92812
92841
  }
92813
92842
  }
92814
92843
  async function launchInstrumented(options) {
92815
92844
  const hostname = options.hostname ?? "127.0.0.1";
92816
- const deadline = Date.now() + (options.readyTimeoutMs ?? 15e3);
92845
+ const readyTimeoutMs = options.readyTimeoutMs ?? DEFAULT_READY_TIMEOUT_MS;
92817
92846
  const child = spawn(
92818
92847
  process.execPath,
92819
92848
  [
@@ -92857,8 +92886,8 @@ ${stderrTailBuffer}`;
92857
92886
  const failed = () => exited ? `server exited before becoming ready. ${explainStartupFailure(stderrWindow())}` : void 0;
92858
92887
  try {
92859
92888
  const controlPort = await pollUntil(
92860
- deadline,
92861
- `control channel in ${options.workDir}`,
92889
+ Date.now() + readyTimeoutMs,
92890
+ () => `control channel in ${options.workDir}`,
92862
92891
  // Several processes may announce a channel (clustered servers); accept
92863
92892
  // the first one that actually answers instead of trusting a filename.
92864
92893
  async () => {
@@ -92888,8 +92917,8 @@ ${stderrTailBuffer}`;
92888
92917
  failed
92889
92918
  );
92890
92919
  await pollUntil(
92891
- deadline,
92892
- `app on ${hostname}:${options.appPort}`,
92920
+ Date.now() + readyTimeoutMs,
92921
+ () => appNeverListened(hostname, options.appPort, readyTimeoutMs, stderrWindow()),
92893
92922
  async () => {
92894
92923
  try {
92895
92924
  await fetch(`http://${hostname}:${options.appPort}/`, { method: "HEAD" });
@@ -92945,6 +92974,7 @@ var RUN_ONLY_FLAGS = [
92945
92974
  ["idleSeconds", "--idle"],
92946
92975
  ["warmupRequests", "--warmup"],
92947
92976
  ["maxOldSpaceMb", "--max-old-space"],
92977
+ ["readyTimeoutSeconds", "--ready-timeout"],
92948
92978
  ["quick", "--quick"],
92949
92979
  ["noResolve", "--no-resolve"],
92950
92980
  ["selfCheck", "--self-check"],
@@ -92989,6 +93019,12 @@ var FLAGS = [
92989
93019
  argName: "<mb>",
92990
93020
  help: "Heap cap of each measured process (default 512) \u2014 raise it for apps whose working set is larger"
92991
93021
  },
93022
+ {
93023
+ flag: "--ready-timeout",
93024
+ value: "int",
93025
+ argName: "<seconds>",
93026
+ help: "Seconds each measured process gets to start listening (default 60) \u2014 raise it for slow-booting apps"
93027
+ },
92992
93028
  {
92993
93029
  flag: "--quick",
92994
93030
  value: "none",
@@ -93060,7 +93096,8 @@ var LIMITS = {
93060
93096
  "--connections": 1e4,
93061
93097
  "--idle": 3600,
93062
93098
  "--warmup": 1e6,
93063
- "--max-old-space": 65536
93099
+ "--max-old-space": 65536,
93100
+ "--ready-timeout": 600
93064
93101
  };
93065
93102
  var MIN_MAX_OLD_SPACE_MB = 128;
93066
93103
  function findSpec(argument) {
@@ -93102,6 +93139,7 @@ function applyNumericFlag(flag, value, options) {
93102
93139
  if (flag === "--idle") options.idleSeconds = parsed;
93103
93140
  if (flag === "--warmup") options.warmupRequests = parsed;
93104
93141
  if (flag === "--max-old-space") options.maxOldSpaceMb = parsed;
93142
+ if (flag === "--ready-timeout") options.readyTimeoutSeconds = parsed;
93105
93143
  return FLAG_OK;
93106
93144
  }
93107
93145
  function applyFlag(spec, value, options) {
@@ -93115,6 +93153,7 @@ function applyFlag(spec, value, options) {
93115
93153
  case "--idle":
93116
93154
  case "--warmup":
93117
93155
  case "--max-old-space":
93156
+ case "--ready-timeout":
93118
93157
  return applyNumericFlag(spec.flag, value, options);
93119
93158
  case "--quick":
93120
93159
  options.quick = true;
@@ -93187,6 +93226,7 @@ function parseCliArgs(argv) {
93187
93226
  idleSeconds: null,
93188
93227
  warmupRequests: null,
93189
93228
  maxOldSpaceMb: null,
93229
+ readyTimeoutSeconds: null,
93190
93230
  quick: false,
93191
93231
  noResolve: false,
93192
93232
  selfCheck: false,
@@ -93869,7 +93909,8 @@ async function runRitual(options, deps = defaultDeps) {
93869
93909
  serverPath: options.serverPath,
93870
93910
  workDir: options.workDir,
93871
93911
  bootstrapPath: options.bootstrapPath,
93872
- ...options.maxOldSpaceMb !== void 0 && { maxOldSpaceMb: options.maxOldSpaceMb }
93912
+ ...options.maxOldSpaceMb !== void 0 && { maxOldSpaceMb: options.maxOldSpaceMb },
93913
+ ...options.readyTimeoutMs !== void 0 && { readyTimeoutMs: options.readyTimeoutMs }
93873
93914
  };
93874
93915
  let app;
93875
93916
  try {
@@ -94780,6 +94821,7 @@ async function measureRoute(context, route, requestPath, index, pass = void 0) {
94780
94821
  ...pass?.cycles !== void 0 ? { cycles: pass.cycles } : options.cycles !== void 0 && { cycles: options.cycles },
94781
94822
  ...options.idleMs !== void 0 && { idleMs: options.idleMs },
94782
94823
  ...options.maxOldSpaceMb !== void 0 && { maxOldSpaceMb: options.maxOldSpaceMb },
94824
+ ...options.readyTimeoutMs !== void 0 && { readyTimeoutMs: options.readyTimeoutMs },
94783
94825
  ...headers !== void 0 && { headers },
94784
94826
  ...routeConfig.abandonAfterMs !== void 0 && {
94785
94827
  abandonAfterMs: routeConfig.abandonAfterMs
@@ -16,6 +16,8 @@ export type CliRunOptions = {
16
16
  idleSeconds: number | null;
17
17
  warmupRequests: number | null;
18
18
  maxOldSpaceMb: number | null;
19
+ /** Seconds each measured process gets to boot before the route is failed. */
20
+ readyTimeoutSeconds: number | null;
19
21
  quick: boolean;
20
22
  noResolve: boolean;
21
23
  selfCheck: boolean;
package/dist/cli.js CHANGED
@@ -22,7 +22,7 @@ import {
22
22
  runSelfCheck,
23
23
  unregisterChild,
24
24
  validateTarget
25
- } from "./chunk-JHOE2RCM.js";
25
+ } from "./chunk-672J2BQO.js";
26
26
  import {
27
27
  classifyTrend
28
28
  } from "./chunk-4FYSLLSX.js";
@@ -933,6 +933,9 @@ async function main() {
933
933
  ...options.idleSeconds !== null && { idleMs: options.idleSeconds * 1e3 },
934
934
  ...options.warmupRequests !== null && { warmupRequests: options.warmupRequests },
935
935
  ...options.maxOldSpaceMb !== null && { maxOldSpaceMb: options.maxOldSpaceMb },
936
+ ...options.readyTimeoutSeconds !== null && {
937
+ readyTimeoutMs: options.readyTimeoutSeconds * 1e3
938
+ },
936
939
  ...options.diffAll && { diffAll: true },
937
940
  ...options.noResolve && { resolveInconclusive: false },
938
941
  ...options.output !== null && { outputDir: options.output },
package/dist/index.js CHANGED
@@ -41,7 +41,7 @@ import {
41
41
  sourceIndexAt,
42
42
  summarizeBaseline,
43
43
  validateTarget
44
- } from "./chunk-JHOE2RCM.js";
44
+ } from "./chunk-672J2BQO.js";
45
45
  import {
46
46
  renderHtmlReport
47
47
  } from "./chunk-YLHE4N5G.js";
@@ -8,6 +8,18 @@ import { type ChildProcess } from "node:child_process";
8
8
  * so `--max-old-space` exists and the chosen value is recorded in `run.json`.
9
9
  */
10
10
  export declare const DEFAULT_MAX_OLD_SPACE_MB = 512;
11
+ /**
12
+ * How long each startup wait gets before the route is called failed.
13
+ *
14
+ * It was 15 s, shared between waiting for the control channel and waiting for
15
+ * the app to listen — so a slow channel spent the app's budget too. Both
16
+ * numbers were also invisible: a real app that needs longer to boot than the
17
+ * tool was willing to wait had no way to say so, and got
18
+ * `timed out waiting for app` on every route (#71). 60 s is what a cold
19
+ * standalone bundle of a couple of thousand modules takes on a laptop with
20
+ * a busy disk, with room to spare; `--ready-timeout` moves it.
21
+ */
22
+ export declare const DEFAULT_READY_TIMEOUT_MS = 60000;
11
23
  export type LaunchOptions = {
12
24
  /** Absolute path to the standalone `server.js` (or any PORT/HOSTNAME-honoring server). */
13
25
  serverPath: string;
@@ -19,6 +31,10 @@ export type LaunchOptions = {
19
31
  bootstrapPath: string;
20
32
  hostname?: string;
21
33
  maxOldSpaceMb?: number;
34
+ /**
35
+ * Budget for each of the two waits below, not for the pair. Default:
36
+ * `DEFAULT_READY_TIMEOUT_MS`.
37
+ */
22
38
  readyTimeoutMs?: number;
23
39
  env?: Record<string, string>;
24
40
  };
@@ -81,6 +97,13 @@ export declare function explainStartupFailure(stderr: string): string;
81
97
  */
82
98
  export declare function stderrShowsHeapExhaustion(stderr: string): boolean;
83
99
  export declare function explainRuntimeFailure(stderr: string, maxOldSpaceMb: number): string;
100
+ /**
101
+ * What to say when the process is alive and answering on its control channel,
102
+ * but never opened the app port. The old message named the port and stopped
103
+ * there, which reads like the tool failed to connect to something that was
104
+ * running. The process is up: what did not happen is the listen.
105
+ */
106
+ export declare function appNeverListened(hostname: string, port: number, budgetMs: number, stderr: string): string;
84
107
  /**
85
108
  * Spawns the measured server in a fresh child process with GC exposed and the
86
109
  * control-channel bootstrap preloaded, and waits until both the app port and
package/dist/ritual.d.ts CHANGED
@@ -20,6 +20,8 @@ export type RitualOptions = {
20
20
  idleMs?: number;
21
21
  /** Old-space cap for the measured process (MB). Default: 512. */
22
22
  maxOldSpaceMb?: number;
23
+ /** How long the process gets to start listening (ms). Default: 60_000. */
24
+ readyTimeoutMs?: number;
23
25
  /** Headers sent with every request during warm-up and load. */
24
26
  headers?: Record<string, string>;
25
27
  /**
package/dist/runner.d.ts CHANGED
@@ -230,6 +230,11 @@ export type RunOptions = {
230
230
  idleMs?: number;
231
231
  /** Old-space cap for each measured process (MB). Default 512. */
232
232
  maxOldSpaceMb?: number;
233
+ /**
234
+ * How long each measured process gets to start listening, in milliseconds.
235
+ * Default: `DEFAULT_READY_TIMEOUT_MS`.
236
+ */
237
+ readyTimeoutMs?: number;
233
238
  /** Also diff routes with a stable verdict. Default false: diffs are slow. */
234
239
  diffAll?: boolean;
235
240
  /** Only measure routes matching these templates or prefixes. */
package/dist/target.d.ts CHANGED
@@ -6,7 +6,11 @@ export declare class TargetError extends Error {
6
6
  }
7
7
  export type ValidatedTarget = {
8
8
  appDir: string;
9
- /** Absolute path to `.next/standalone/server.js`. */
9
+ /**
10
+ * Absolute path to the standalone `server.js`. At the root of
11
+ * `.next/standalone` for a single-package app; under the app's path relative
12
+ * to the workspace root for a monorepo.
13
+ */
10
14
  standaloneServer: string;
11
15
  appPaths: AppPathsManifest;
12
16
  pages: PagesManifest;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-leak",
3
- "version": "0.11.0",
3
+ "version": "0.11.1",
4
4
  "description": "Find out whether your Next.js app actually leaks memory — how much, on which route, and whose fault it is.",
5
5
  "keywords": [
6
6
  "nextjs",