{"record":{"id":"e0c26b6da57cc1c0","repo":"nodejs/node","slug":"expected-opts-maxbuffersize-to-be-a-positive-finit","errorCode":null,"errorMessage":"expected opts.maxBufferSize to be a positive finite number, got ${maxBufferSize}","messagePattern":"expected opts\\.maxBufferSize to be a positive finite number, got (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"deps/undici/src/lib/interceptor/deduplicate.js","lineNumber":45,"sourceCode":"    throw new TypeError(`expected opts.methods to be an array, got ${typeof methods}`)\n  }\n\n  for (const method of methods) {\n    if (!util.safeHTTPMethods.includes(method)) {\n      throw new TypeError(`expected opts.methods to only contain safe HTTP methods, got ${method}`)\n    }\n  }\n\n  if (!Array.isArray(skipHeaderNames)) {\n    throw new TypeError(`expected opts.skipHeaderNames to be an array, got ${typeof skipHeaderNames}`)\n  }\n\n  if (!Array.isArray(excludeHeaderNames)) {\n    throw new TypeError(`expected opts.excludeHeaderNames to be an array, got ${typeof excludeHeaderNames}`)\n  }\n\n  if (!Number.isFinite(maxBufferSize) || maxBufferSize <= 0) {\n    throw new TypeError(`expected opts.maxBufferSize to be a positive finite number, got ${maxBufferSize}`)\n  }\n\n  // Convert to lowercase Set for case-insensitive header matching\n  const skipHeaderNamesSet = new Set(skipHeaderNames.map(name => name.toLowerCase()))\n\n  // Convert to lowercase Set for case-insensitive header exclusion from deduplication key\n  const excludeHeaderNamesSet = new Set(excludeHeaderNames.map(name => name.toLowerCase()))\n\n  /**\n   * Map of pending requests for deduplication\n   * @type {Map<string, DeduplicationHandler>}\n   */\n  const pendingRequests = new Map()\n\n  return dispatch => {\n    return (opts, handler) => {\n      if (opts.upgrade || methods.includes(opts.method) === false) {\n        return dispatch(opts, handler)","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/undici/src/lib/interceptor/deduplicate.js#L27-L63","documentation":"Thrown by the deduplicate interceptor when `maxBufferSize` (default `5 * 1024 * 1024` bytes) is not a positive finite number. The deduplicate handler buffers the leading bytes of a response so it can replay them to wait-listed callers before streaming; once the buffer exceeds `maxBufferSize` it stops accepting new waiters and sends extra requests independently. An invalid cap would either never allow coalescing (zero/negative) or permit unbounded memory growth (`Infinity`), so the factory rejects both.","triggerScenarios":"Passing `maxBufferSize: 0`, a negative number, `NaN`, `Infinity`, or a non-number (string `'5mb'`). `Number.isFinite` rules out NaN and ±Infinity, and `maxBufferSize <= 0` rules out zero and negatives. Default is 5 MiB.","commonSituations":"Reading a size from env/config as a string (e.g. `process.env.DEDUP_BUFFER` without `Number()`); using a human-readable size like `'5mb'` without parsing; setting 0 thinking it disables buffering (it does not — it errors).","solutions":["Pass a positive finite integer byte count, e.g. `maxBufferSize: 10 * 1024 * 1024` for 10 MiB.","If loading from config/env, coerce and parse: `Number(process.env.DEDUP_BUFFER ?? 5_242_880)` and validate `Number.isFinite(v) && v > 0`.","Do not pass `0` to 'disable' buffering — omit the option to keep the 5 MiB default, or raise it if responses are large."],"exampleFix":"// before\ndeduplicate({ maxBufferSize: process.env.DEDUP_BUFFER }) // env is a string '5242880'\ndeduplicate({ maxBufferSize: 0 })\n\n// after\ndeduplicate({ maxBufferSize: Number(process.env.DEDUP_BUFFER) })\ndeduplicate({ maxBufferSize: 10 * 1024 * 1024 })","handlingStrategy":"validation","validationCode":"function validateMaxBufferSize(v) {\n  const n = Number(v)\n  if (!Number.isFinite(n) || n <= 0) {\n    throw new TypeError('maxBufferSize must be a positive finite number')\n  }\n  return n\n}","typeGuard":"function isPositiveFinite(v) {\n  return typeof v === 'number' && Number.isFinite(v) && v > 0\n}","tryCatchPattern":null,"preventionTips":["Always coerce env/config sizes with Number() and parse human units.","Never pass 0 to 'disable' buffering."],"tags":["undici","interceptor","deduplicate","memory","validation","config"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}