{"record":{"id":"59589baee2b4766e","repo":"denoland/deno","slug":"err-out-of-range-59589b","errorCode":"ERR_OUT_OF_RANGE","errorMessage":"The value of \"${name}\" is out of range. It must be a non-negative finite number. Received ${msecs}","messagePattern":"The value of \"(.+?)\" is out of range\\. It must be a non-negative finite number\\. Received (.+?)","errorType":"validation","errorClass":"ERR_OUT_OF_RANGE","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/internal/timers.mjs","lineNumber":366,"sourceCode":"\nTimeout.prototype.hasRef = function () {\n  return this[kRefed];\n};\n\nTimeout.prototype[SymbolToPrimitive] = function () {\n  return this[kTimerId];\n};\n\n/**\n * @param {number} msecs\n * @param {string} name\n * @returns\n */\nfunction getTimerDuration(msecs, name) {\n  validateNumber(msecs, name);\n\n  if (msecs < 0 || !NumberIsFinite(msecs)) {\n    throw new ERR_OUT_OF_RANGE(name, \"a non-negative finite number\", msecs);\n  }\n\n  // Ensure that msecs fits into signed int32\n  if (msecs > TIMEOUT_MAX) {\n    lazyProcess().default.emitWarning(\n      `${msecs} does not fit into a 32-bit signed integer.` +\n        `\\nTimer duration was truncated to ${TIMEOUT_MAX}.`,\n      \"TimeoutOverflowWarning\",\n    );\n\n    return TIMEOUT_MAX;\n  }\n\n  return msecs;\n}\n\nfunction setUnrefTimeout(callback, timeout, ...args) {\n  validateFunction(callback, \"callback\");","sourceCodeStart":348,"sourceCodeEnd":384,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/internal/timers.mjs#L348-L384","documentation":"getTimerDuration validates timeout durations inside Deno's node compat layer and throws ERR_OUT_OF_RANGE for negative or non-finite numbers. Its active call sites are stream/net setTimeout (ext/node/polyfills/internal/stream_base_commons.ts:392, i.e. socket.setTimeout(msecs)), http.request({ timeout }) (ext/node/polyfills/_http_client.js:649), and ClientRequest.prototype.setTimeout (line 1626) — the global setTimeout/setInterval are NOT affected (they clamp instead). Values above 2147483647 do not throw; they are truncated with a TimeoutOverflowWarning.","triggerScenarios":"socket.setTimeout(-1); req.setTimeout(Infinity); http.request(url, { timeout: -1 }); duration computed as a - b going negative, or 0/0 producing NaN and forwarded to setTimeout on the socket.","commonSituations":"Config-driven timeouts where 'disabled' is encoded as -1 or Infinity instead of 0/omission; idletimeout math with unsigned subtraction bugs; passing a value parsed from a header/query (NaN) straight into socket.setTimeout.","solutions":["Use 0 (or omit the call) to disable a socket timeout — never a negative number","Sanitize: const t = Number.isFinite(ms) && ms > 0 ? Math.min(ms, 2147483647) : 0","Clamp Infinity to TIMEOUT_MAX (2147483647) if you really want 'very long'"],"exampleFix":"// before\nconst timeoutMs = cfg.disabled ? -1 : 5000;\nsocket.setTimeout(timeoutMs);\n\n// after\nconst timeoutMs = cfg.disabled ? 0 : 5000;\nif (timeoutMs > 0) socket.setTimeout(timeoutMs); else socket.setTimeout(0);","handlingStrategy":"validation","validationCode":"const TIMEOUT_MAX = 2147483647;\n\nfunction sanitizeTimeout(ms: unknown): number {\n  const n = Number(ms);\n  if (!Number.isFinite(n) || n < 0) return 0; // 0 disables the socket timeout\n  return Math.min(n, TIMEOUT_MAX);\n}\n\nsocket.setTimeout(sanitizeTimeout(cfg.timeout));","typeGuard":"const isValidTimeout = (ms: unknown): ms is number =>\n  typeof ms === 'number' && Number.isFinite(ms) && ms >= 0;","tryCatchPattern":"try {\n  req.setTimeout(ms);\n} catch (err) {\n  if (err?.code === 'ERR_OUT_OF_RANGE') req.setTimeout(0);\n  else throw err;\n}","preventionTips":["Encode 'disabled' as 0, never -1 or Infinity, in timeout config","Remember only stream/http setTimeout paths validate; values above 2^31-1 are silently truncated with a warning"],"tags":["timers","net","http","node-compat","deno","range-error"],"backgroundTag":"invalid-timeout-duration","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}