{"record":{"id":"c12435333278e771","repo":"denoland/deno","slug":"cannot-read-url-request-closed-c12435","errorCode":null,"errorMessage":"Cannot read url: request closed","messagePattern":"Cannot read url: request closed","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/fetch/23_request.js","lineNumber":177,"sourceCode":"    clientRid: null,\n    blobUrlEntry,\n    url() {\n      if (this.urlListProcessed[0] === undefined) {\n        try {\n          this.urlListProcessed[0] = this.urlList[0]();\n        } catch {\n          throw new TypeError(\"cannot read url: request closed\");\n        }\n      }\n      return this.urlListProcessed[0];\n    },\n    currentUrl() {\n      const currentIndex = this.urlList.length - 1;\n      if (this.urlListProcessed[currentIndex] === undefined) {\n        try {\n          this.urlListProcessed[currentIndex] = this.urlList[currentIndex]();\n        } catch {\n          throw new TypeError(\"Cannot read url: request closed\");\n        }\n      }\n      return this.urlListProcessed[currentIndex];\n    },\n  };\n}\n\n/**\n * https://fetch.spec.whatwg.org/#concept-request-clone\n * @param {InnerRequest} request\n * @param {boolean} skipBody\n * @returns {InnerRequest}\n */\nfunction cloneInnerRequest(request, skipBody = false) {\n  const headerList = ArrayPrototypeMap(\n    request.headerList,\n    (x) => [x[0], x[1]],\n  );","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/fetch/23_request.js#L159-L195","documentation":"InnerRequest.currentUrl() lazily resolves the most recent URL in the request's URL list (used during redirect following) by calling the stored urlList callback. For op-backed requests that callback is a native read; if the request resource has been closed by the time currentUrl() runs, the native call throws and is re-thrown as TypeError \"Cannot read url: request closed\".","triggerScenarios":"Redirect handling (fetch internals calling currentUrl on redirect) against an op-backed request that got closed mid-flight; user code or libraries that walk a server request's url list after the connection ended.","commonSituations":"Calling fetch() with an already-consumed server-side Request; proxies that forward the incoming request object asynchronously after responding; tests that reuse a request across ticks after the server released it.","solutions":["Forward a fresh Request built from snapshotted data instead of reusing the server request object","Perform redirect-following fetches while the original request is still alive (start them in the handler)","Capture req.url up front and construct a new Request(url, { method, headers, body }) for deferred work"],"exampleFix":"// before\nDeno.serve((req) => {\n  jobs.push(() => fetch(req)); // later: TypeError: Cannot read url: request closed\n  return new Response(\"accepted\");\n});\n\n// after\nDeno.serve((req) => {\n  const snapshot = { url: req.url, method: req.method, headers: [...req.headers] };\n  jobs.push(() => fetch(snapshot.url, { method: snapshot.method, headers: snapshot.headers }));\n  return new Response(\"accepted\");\n});","handlingStrategy":"try-catch","validationCode":"// Capture before the handler returns, then re-fetch with explicit data:\nfunction forwardLater(req) {\n  const snapshot = { url: req.url, method: req.method, headers: [...req.headers] };\n  return () => fetch(snapshot.url, { method: snapshot.method, headers: snapshot.headers });\n}","typeGuard":null,"tryCatchPattern":"try {\n  await fetch(req); // may hit currentUrl() on redirects if the source closed\n} catch (err) {\n  if (err instanceof TypeError && err.message.includes(\"request closed\")) {\n    // rebuild from snapshot and retry once\n  } else throw err;\n}","preventionTips":["Never pass an op-backed server Request into fetch() after the handler returned","Start forwarding fetches synchronously inside the handler","Build detached requests from snapshotted data for deferred/queued work"],"tags":["fetch","request","url","resource-lifecycle","redirect"],"backgroundTag":"use-after-close","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}