{"version":3,"file":"retry-handler.mjs","sources":["../../../lib/handler/retry-handler.js"],"sourcesContent":["'use strict'\nconst assert = require('node:assert')\n\nconst { kRetryHandlerDefaultRetry } = require('../core/symbols')\nconst { RequestRetryError } = require('../core/errors')\nconst {\n  isDisturbed,\n  parseRangeHeader,\n  wrapRequestBody\n} = require('../core/util')\n\nfunction calculateRetryAfterHeader (retryAfter) {\n  const retryTime = new Date(retryAfter).getTime()\n  return isNaN(retryTime) ? null : retryTime - Date.now()\n}\n\nfunction validatePartialResponseContentLength (headers, range, statusCode, retryCount) {\n  const contentLength = headers['content-length']\n  if (contentLength == null) {\n    return\n  }\n\n  if (!Number.isFinite(range.start) || !Number.isFinite(range.end)) {\n    return\n  }\n\n  const length = Number(contentLength)\n  const expectedLength = range.end - range.start + 1\n  if (!Number.isFinite(length) || length !== expectedLength) {\n    throw new RequestRetryError('Content-Length mismatch', statusCode, {\n      headers,\n      data: { count: retryCount }\n    })\n  }\n}\n\n// A stable controller handed to the downstream handler for the lifetime of the\n// request. Each transparent retry/resume is a *separate* dispatch with its\n// *own* connection controller. Without a stable proxy the downstream body keeps\n// flow-controlling the original (now-dead) controller while data flows on the\n// new one: backpressure pauses the new connection's controller, but the\n// consumer's resume() targets the old one, so the resumed body stalls forever.\n// The proxy always forwards to the controller of the currently active connection.\nclass RetryController {\n  constructor () {\n    this.target = null\n  }\n\n  pause () { this.target?.pause() }\n  resume () { this.target?.resume() }\n  abort (reason) { this.target?.abort(reason) }\n  get paused () { return this.target?.paused ?? false }\n  get aborted () { return this.target?.aborted ?? false }\n  get reason () { return this.target?.reason ?? null }\n  get rawHeaders () { return this.target?.rawHeaders ?? null }\n  get rawTrailers () { return this.target?.rawTrailers ?? null }\n}\n\nclass RetryHandler {\n  constructor (opts, { dispatch, handler }) {\n    const { retryOptions, ...dispatchOpts } = opts\n    const {\n      // Retry scoped\n      retry: retryFn,\n      maxRetries,\n      maxTimeout,\n      minTimeout,\n      timeoutFactor,\n      // Response scoped\n      methods,\n      errorCodes,\n      retryAfter,\n      statusCodes,\n      throwOnError\n    } = retryOptions ?? {}\n\n    this.error = null\n    this.dispatch = dispatch\n    this.handler = handler\n    this.opts = { ...dispatchOpts, body: wrapRequestBody(opts.body) }\n    this.retryOpts = {\n      throwOnError: throwOnError ?? true,\n      retry: retryFn ?? RetryHandler[kRetryHandlerDefaultRetry],\n      retryAfter: retryAfter ?? true,\n      maxTimeout: maxTimeout ?? 30 * 1000, // 30s,\n      minTimeout: minTimeout ?? 500, // .5s\n      timeoutFactor: timeoutFactor ?? 2,\n      maxRetries: maxRetries ?? 5,\n      // What errors we should retry\n      methods: methods ?? ['GET', 'HEAD', 'OPTIONS', 'PUT', 'DELETE', 'TRACE', 'QUERY'],\n      // Indicates which errors to retry\n      statusCodes: statusCodes ?? [500, 502, 503, 504, 429],\n      // List of errors to retry\n      errorCodes: errorCodes ?? [\n        'ECONNRESET',\n        'ECONNREFUSED',\n        'ENOTFOUND',\n        'ENETDOWN',\n        'ENETUNREACH',\n        'EHOSTDOWN',\n        'EHOSTUNREACH',\n        'EPIPE',\n        'UND_ERR_SOCKET'\n      ]\n    }\n\n    this.retryCount = 0\n    this.retryCountCheckpoint = 0\n    this.headersSent = false\n    this.start = 0\n    this.end = null\n    this.etag = null\n    this.statusCode = null\n    this.headers = null\n    this.controllerProxy = new RetryController()\n  }\n\n  onResponseStartWithRetry (controller, statusCode, headers, statusMessage, err) {\n    if (this.retryOpts.throwOnError) {\n      // Preserve old behavior for status codes that are not eligible for retry\n      if (this.retryOpts.statusCodes.includes(statusCode) === false) {\n        this.headersSent = true\n        this.handler.onResponseStart?.(this.controllerProxy, statusCode, headers, statusMessage)\n      } else {\n        this.error = err\n      }\n\n      return\n    }\n\n    if (isDisturbed(this.opts.body)) {\n      this.headersSent = true\n      this.handler.onResponseStart?.(this.controllerProxy, statusCode, headers, statusMessage)\n      return\n    }\n\n    function shouldRetry (passedErr) {\n      if (passedErr) {\n        this.headersSent = true\n        this.handler.onResponseStart?.(this.controllerProxy, statusCode, headers, statusMessage)\n        controller.resume()\n        return\n      }\n\n      this.error = err\n      controller.resume()\n    }\n\n    // The pause()/resume() pair (here and in shouldRetry) acts on THIS\n    // connection's controller -- never the downstream proxy. We hold this exact\n    // connection while the retry policy decides (possibly after a timeout) and\n    // must resume the same one. Routing this through controllerProxy would risk\n    // resuming a different connection if a later dispatch re-points the proxy in\n    // between, leaving this one paused forever -- the very stall the proxy exists\n    // to prevent.\n    controller.pause()\n    this.retryOpts.retry(\n      err,\n      {\n        state: { counter: this.retryCount },\n        opts: { retryOptions: this.retryOpts, ...this.opts }\n      },\n      shouldRetry.bind(this)\n    )\n  }\n\n  onRequestStart (controller, context) {\n    // request.js creates a fresh RequestController per dispatch and passes that\n    // same instance to every later callback of the dispatch. onRequestStart is\n    // the first callback (it is where the controller is created), so re-pointing\n    // the proxy here is enough to keep it on the active connection across every\n    // transparent retry/resume.\n    this.controllerProxy.target = controller\n    if (!this.headersSent) {\n      this.handler.onRequestStart?.(this.controllerProxy, context)\n    }\n  }\n\n  onRequestUpgrade (_controller, statusCode, headers, socket) {\n    this.handler.onRequestUpgrade?.(this.controllerProxy, statusCode, headers, socket)\n  }\n\n  static [kRetryHandlerDefaultRetry] (err, { state, opts }, cb) {\n    const { statusCode, code, headers } = err\n    const { method, retryOptions } = opts\n    const {\n      maxRetries,\n      minTimeout,\n      maxTimeout,\n      timeoutFactor,\n      statusCodes,\n      errorCodes,\n      methods\n    } = retryOptions\n    const { counter } = state\n\n    // Any code that is not a Undici's originated and allowed to retry\n    if (code && code !== 'UND_ERR_REQ_RETRY' && !errorCodes.includes(code)) {\n      cb(err)\n      return\n    }\n\n    // If a set of method are provided and the current method is not in the list\n    if (Array.isArray(methods) && !methods.includes(method)) {\n      cb(err)\n      return\n    }\n\n    // If a set of status code are provided and the current status code is not in the list\n    if (\n      statusCode != null &&\n      Array.isArray(statusCodes) &&\n      !statusCodes.includes(statusCode)\n    ) {\n      cb(err)\n      return\n    }\n\n    // If we reached the max number of retries\n    if (counter > maxRetries) {\n      cb(err)\n      return\n    }\n\n    let retryAfterHeader = headers?.['retry-after']\n    if (retryAfterHeader) {\n      retryAfterHeader = Number(retryAfterHeader)\n      retryAfterHeader = Number.isNaN(retryAfterHeader)\n        ? calculateRetryAfterHeader(headers['retry-after'])\n        : retryAfterHeader * 1e3 // Retry-After is in seconds\n    }\n\n    const retryTimeout =\n      retryAfterHeader === 0\n        ? 0\n        : retryAfterHeader > 0\n          ? Math.min(retryAfterHeader, maxTimeout)\n          : Math.min(minTimeout * timeoutFactor ** (counter - 1), maxTimeout)\n\n    setTimeout(() => cb(null), retryTimeout)\n  }\n\n  onResponseStart (controller, statusCode, headers, statusMessage) {\n    if (statusCode < 200) {\n      this.handler.onResponseStart?.(this.controllerProxy, statusCode, headers, statusMessage)\n      return\n    }\n\n    this.error = null\n    this.retryCount += 1\n    this.statusCode = statusCode\n    this.headers = headers\n\n    if (statusCode >= 300) {\n      const err = new RequestRetryError('Request failed', statusCode, {\n        headers,\n        data: {\n          count: this.retryCount\n        }\n      })\n\n      this.onResponseStartWithRetry(controller, statusCode, headers, statusMessage, err)\n      return\n    }\n\n    // Checkpoint for resume from where we left it\n    if (this.headersSent) {\n      // Only Partial Content 206 supposed to provide Content-Range,\n      // any other status code that partially consumed the payload\n      // should not be retried because it would result in downstream\n      // wrongly concatenate multiple responses.\n      if (statusCode !== 206 && (this.start > 0 || statusCode !== 200)) {\n        throw new RequestRetryError('server does not support the range header and the payload was partially consumed', statusCode, {\n          headers,\n          data: { count: this.retryCount }\n        })\n      }\n\n      const contentRange = parseRangeHeader(headers['content-range'])\n      // If no content range\n      if (!contentRange) {\n        // We always throw here as we want to indicate that we entred unexpected path\n        throw new RequestRetryError('Content-Range mismatch', statusCode, {\n          headers,\n          data: { count: this.retryCount }\n        })\n      }\n\n      // Let's start with a weak etag check\n      if (this.etag != null && this.etag !== headers.etag) {\n        // We always throw here as we want to indicate that we entred unexpected path\n        throw new RequestRetryError('ETag mismatch', statusCode, {\n          headers,\n          data: { count: this.retryCount }\n        })\n      }\n\n      validatePartialResponseContentLength(headers, contentRange, statusCode, this.retryCount)\n\n      const { start, size, end = size ? size - 1 : null } = contentRange\n\n      assert(this.start === start, 'content-range mismatch')\n      assert(this.end == null || this.end === end, 'content-range mismatch')\n\n      return\n    }\n\n    if (this.end == null) {\n      if (statusCode === 206) {\n        // First time we receive 206\n        const range = parseRangeHeader(headers['content-range'])\n\n        if (range == null || range.end == null) {\n          this.headersSent = true\n          this.handler.onResponseStart?.(\n            this.controllerProxy,\n            statusCode,\n            headers,\n            statusMessage\n          )\n          return\n        }\n\n        validatePartialResponseContentLength(headers, range, statusCode, this.retryCount)\n\n        const { start, size, end = size ? size - 1 : null } = range\n        assert(\n          start != null && Number.isFinite(start),\n          'content-range mismatch'\n        )\n        assert(end != null && Number.isFinite(end), 'invalid content-length')\n\n        this.start = start\n        this.end = end\n      }\n\n      // We make our best to checkpoint the body for further range headers\n      if (this.end == null && this.opts.method !== 'HEAD') {\n        const contentLength = headers['content-length']\n        this.end = contentLength != null ? Number(contentLength) - 1 : null\n      }\n\n      assert(Number.isFinite(this.start))\n      assert(\n        this.end == null || Number.isFinite(this.end),\n        'invalid content-length'\n      )\n\n      this.resume = true\n      this.etag = headers.etag != null ? headers.etag : null\n\n      // Weak etags are not useful for comparison nor cache\n      // for instance not safe to assume if the response is byte-per-byte\n      // equal\n      if (\n        this.etag != null &&\n        this.etag[0] === 'W' &&\n        this.etag[1] === '/'\n      ) {\n        this.etag = null\n      }\n\n      this.headersSent = true\n      this.handler.onResponseStart?.(\n        this.controllerProxy,\n        statusCode,\n        headers,\n        statusMessage\n      )\n    } else {\n      throw new RequestRetryError('Request failed', statusCode, {\n        headers,\n        data: { count: this.retryCount }\n      })\n    }\n  }\n\n  onResponseData (_controller, chunk) {\n    if (this.error) {\n      return\n    }\n\n    this.start += chunk.length\n\n    this.handler.onResponseData?.(this.controllerProxy, chunk)\n  }\n\n  onResponseEnd (_controller, trailers) {\n    if (this.error && this.retryOpts.throwOnError) {\n      throw this.error\n    }\n\n    if (!this.error) {\n      // Verify that the received body length matches the expected range\n      // when we have a finite end position (from Content-Length or Content-Range)\n      if (this.end != null && Number.isFinite(this.end)) {\n        if (this.start !== this.end + 1) {\n          throw new RequestRetryError('Content-Range mismatch', this.statusCode, {\n            headers: this.headers,\n            data: { count: this.retryCount }\n          })\n        }\n      }\n      this.retryCount = 0\n      return this.handler.onResponseEnd?.(this.controllerProxy, trailers)\n    }\n\n    this.retry()\n  }\n\n  retry () {\n    if (this.start !== 0) {\n      const headers = { range: `bytes=${this.start}-${this.end ?? ''}` }\n\n      // Weak etag check - weak etags will make comparison algorithms never match\n      if (this.etag != null) {\n        headers['if-match'] = this.etag\n      }\n\n      this.opts = {\n        ...this.opts,\n        headers: {\n          ...this.opts.headers,\n          ...headers\n        }\n      }\n    }\n\n    try {\n      this.retryCountCheckpoint = this.retryCount\n      this.dispatch(this.opts, this)\n    } catch (err) {\n      this.handler.onResponseError?.(this.controllerProxy, err)\n    }\n  }\n\n  onResponseError (controller, err) {\n    // controller is THIS failed connection (not the proxy): we inspect whether\n    // the consumer aborted it to decide retry-vs-propagate.\n    if (controller?.aborted || isDisturbed(this.opts.body)) {\n      this.handler.onResponseError?.(this.controllerProxy, err)\n      return\n    }\n\n    function shouldRetry (returnedErr) {\n      if (!returnedErr) {\n        this.retry()\n        return\n      }\n\n      this.handler?.onResponseError?.(this.controllerProxy, returnedErr)\n    }\n\n    // We reconcile in case of a mix between network errors\n    // and server error response\n    if (this.retryCount - this.retryCountCheckpoint > 0) {\n      // We count the difference between the last checkpoint and the current retry count\n      this.retryCount =\n        this.retryCountCheckpoint +\n        (this.retryCount - this.retryCountCheckpoint)\n    } else {\n      this.retryCount += 1\n    }\n\n    this.retryOpts.retry(\n      err,\n      {\n        state: { counter: this.retryCount },\n        opts: { retryOptions: this.retryOpts, ...this.opts }\n      },\n      shouldRetry.bind(this)\n    )\n  }\n}\n\nmodule.exports = RetryHandler\n"],"names":["assert","require$$0","kRetryHandlerDefaultRetry","require$$1","RequestRetryError","require$$2","isDisturbed","parseRangeHeader","wrapRequestBody","require$$3","validatePartialResponseContentLength","headers","range","statusCode","retryCount","contentLength","Number","isFinite","start","end","length","expectedLength","data","count","RetryController","constructor","this","target","pause","resume","abort","reason","paused","aborted","rawHeaders","rawTrailers","RetryHandler","opts","dispatch","handler","retryOptions","dispatchOpts","retry","retryFn","maxRetries","maxTimeout","minTimeout","timeoutFactor","methods","errorCodes","retryAfter","statusCodes","throwOnError","error","body","retryOpts","retryCountCheckpoint","headersSent","etag","controllerProxy","onResponseStartWithRetry","controller","statusMessage","err","includes","onResponseStart","state","counter","passedErr","bind","onRequestStart","context","onRequestUpgrade","_controller","socket","cb","code","method","Array","isArray","retryAfterHeader","isNaN","retryTime","Date","getTime","now","calculateRetryAfterHeader","retryTimeout","Math","min","setTimeout","contentRange","size","onResponseData","chunk","onResponseEnd","trailers","onResponseError","returnedErr","retryHandler"],"mappings":"wPACA,MAAMA,OAASC,YAETC,2BAAgCC,kBAChCC,mBAAwBC,QACxBC,YACOC,iBACKC,iBAEdC,KAOJ,SAASC,qCAAsCC,QAASC,MAAOC,WAAYC,YACzE,MAAMC,cAAgBJ,QAAQ,kBAC9B,GAAqB,MAAjBI,cACF,OAGF,IAAKC,OAAOC,SAASL,MAAMM,SAAWF,OAAOC,SAASL,MAAMO,KAC1D,OAGF,MAAMC,OAASJ,OAAOD,eAChBM,eAAiBT,MAAMO,IAAMP,MAAMM,MAAQ,EACjD,IAAKF,OAAOC,SAASG,SAAWA,SAAWC,eACzC,MAAM,IAAIjB,kBAAkB,0BAA2BS,WAAY,CACjEF,QACAW,KAAM,CAAEC,MAAOT,aAGrB;;;;;;;kFASA;MAAMU,gBACJ,WAAAC,GACEC,KAAKC,OAAS,IAClB,CAEE,KAAAC,GAAWF,KAAKC,QAAQC,OAAO,CAC/B,MAAAC,GAAYH,KAAKC,QAAQE,QAAQ,CACjC,KAAAC,CAA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