{"record":{"id":"a7bdfe16b357056f","repo":"nodejs/node","slug":"und-err-aborted","errorCode":"UND_ERR_ABORTED","errorMessage":"Response size (${contentLength}) larger than maxSize (${this.#maxSize})","messagePattern":"Response size \\((.+?)\\) larger than maxSize \\((.+?)\\)","errorType":"exception","errorClass":"RequestAbortedError","httpStatus":null,"severity":"error","filePath":"deps/undici/src/lib/interceptor/dump.js","lineNumber":41,"sourceCode":"  }\n\n  #abort (reason) {\n    this.aborted = true\n    this.reason = reason\n  }\n\n  onRequestStart (controller, context) {\n    controller.abort = this.#abort.bind(this)\n    this.#controller = controller\n\n    return super.onRequestStart(controller, context)\n  }\n\n  onResponseStart (controller, statusCode, headers, statusMessage) {\n    const contentLength = headers['content-length']\n\n    if (contentLength != null && contentLength > this.#maxSize) {\n      throw new RequestAbortedError(\n        `Response size (${contentLength}) larger than maxSize (${\n          this.#maxSize\n        })`\n      )\n    }\n\n    if (this.aborted === true) {\n      return true\n    }\n\n    return super.onResponseStart(controller, statusCode, headers, statusMessage)\n  }\n\n  onResponseError (controller, err) {\n    if (this.#dumped) {\n      return\n    }\n","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/undici/src/lib/interceptor/dump.js#L23-L59","documentation":"Thrown at runtime by the dump interceptor's `onResponseStart` (a `RequestAbortedError`, code `UND_ERR_ABORTED`) when the response's `content-length` header exceeds the configured `maxSize`. Unlike the constructor validation, this fires during an actual request once the server's headers arrive: the interceptor refuses to buffer a body it knows will overflow the cap and aborts the request instead. This protects memory from oversized responses.","triggerScenarios":"A server responds with `content-length: 10485760` (10 MiB) while `maxSize` is 1 MiB (the default). The check is `contentLength != null && contentLength > this.#maxSize`. The guard only fires when `content-length` is present — chunked/unknown-length responses are checked byte-by-byte later (`onResponseData` accumulates `#size`).","commonSituations":"Downloading files through an interceptor pipeline that includes dump; pointing a dump-instrumented client at an endpoint that returns large JSON/HTML; forgetting that the default cap is only 1 MiB; legitimate large payloads (media, logs) hitting an instrumentation interceptor.","solutions":["Raise `maxSize`/`dumpMaxSize` to comfortably exceed the largest expected `content-length`.","Remove the dump interceptor from code paths that legitimately stream large bodies.","Handle the abort in a try/catch around `fetch`/`request` and fall back to a streaming read without the dump interceptor.","If the size is genuinely unexpected (server returning a huge error page), treat the abort as a signal to inspect the upstream response."],"exampleFix":"// before\nnew Agent().compose([dump()]) // default maxSize 1 MiB\nawait agent.request({ origin, path, method: 'GET' }) // server sends 5 MiB\n\n// after\nnew Agent().compose([dump({ maxSize: 16 * 1024 * 1024 })]) // 16 MiB cap\nawait agent.request({ origin, path, method: 'GET' })","handlingStrategy":"try-catch","validationCode":"function dumpMaxSizeFor(expectedMaxBytes) {\n  // size the dump cap above the largest legitimate content-length\n  return Math.max(1024 * 1024, Math.ceil(expectedMaxBytes * 1.5))\n}","typeGuard":null,"tryCatchPattern":"try {\n  await agent.request({ method: 'GET', origin, path })\n} catch (err) {\n  if (err.code === 'UND_ERR_ABORTED' && /larger than maxSize/.test(err.message)) {\n    // server sent more than dumpMaxSize; re-issue without the dump interceptor\n    // or raise maxSize and retry\n  } else {\n    throw err\n  }\n}","preventionTips":["Size dumpMaxSize above the largest expected content-length plus headroom.","Keep the dump interceptor off code paths that stream large bodies.","Inspect the content-length of large/unexpected responses as a signal."],"tags":["undici","interceptor","dump","response-size","abort","runtime","memory"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}