{"record":{"id":"9230912a4785db71","repo":"denoland/deno","slug":"error","errorCode":null,"errorMessage":"${error}","messagePattern":"\\$\\{error\\}","errorType":"exception","errorClass":"Http","httpStatus":null,"severity":"error","filePath":"ext/http/00_serve.ts","lineNumber":1580,"sourceCode":"  let ref = true;\n  let currentPromise = null;\n\n  // Run the server\n  const finished = (async () => {\n    const rid = context.serverRid;\n    try {\n      currentPromise = op_http_wait(rid);\n      if (!ref) {\n        core.unrefOpPromise(currentPromise);\n      }\n      await currentPromise;\n      currentPromise = null;\n    } catch (error) {\n      if (\n        !ObjectPrototypeIsPrototypeOf(BadResourcePrototype, error) &&\n        !ObjectPrototypeIsPrototypeOf(InterruptedPrototype, error)\n      ) {\n        throw new Deno.errors.Http(error);\n      }\n    }\n\n    try {\n      if (!context.closing && !context.closed) {\n        context.closing = await op_http_close(rid, false);\n        context.close();\n      }\n\n      await context.closing;\n    } catch (error) {\n      if (ObjectPrototypeIsPrototypeOf(InterruptedPrototype, error)) {\n        return;\n      }\n      if (ObjectPrototypeIsPrototypeOf(BadResourcePrototype, error)) {\n        return;\n      }\n","sourceCodeStart":1562,"sourceCodeEnd":1598,"githubUrl":"https://github.com/denoland/deno/blob/abd22074e47c6a5cd14e9e4e84743f084aa5a575/ext/http/00_serve.ts#L1562-L1598","documentation":"Thrown as `new Deno.errors.Http(error)` inside the `finished` promise of an HTTP server started on an existing listener or connection (the `serveHttpOn` path used by `Deno.serveHttp(listener)` / serving over a supplied `Deno.Conn`). The serve loop awaits `op_http_wait(serverRid)`; the two benign shutdown errors (BadResource, Interrupted) are deliberately swallowed, so any other op failure is wrapped in `Deno.errors.Http` and rejects the promise stored on `server.finished`. The message is the stringified inner error, so the real cause lives in the wrapped value.","triggerScenarios":"Awaiting (or never awaiting) `server.finished` / the object returned by `Deno.serveHttp(listener)` when the underlying server resource fails abnormally: the OS-level listener or connection is torn down unexpectedly (fd force-closed by a supervisor, network interface drop, socket error), or an internal hyper/ops error escapes the wait op. Anything that is not a clean close becomes this wrapped error.","commonSituations":"Running `Deno.serveHttp` on a manually managed `Deno.Listener`/`Deno.Conn` under process supervisors or in tests that close raw resources; abrupt container/Pod network teardown; unhandled-rejection reports surfacing late because nothing awaited `server.finished`.","solutions":["Catch the rejection on `server.finished` and inspect the wrapped inner error (message / `cause`) to find the real OS-level cause","Manage lifecycle only through the returned server object (`shutdown()`, `finished`) — never close the raw `Deno.Listener`/`Deno.Conn` it was built on","If the inner error is an OS errno (EMFILE, ECONNRESET, EBADF), check fd limits and network health","Upgrade Deno — several wrapped-error and shutdown-path bugs have been fixed over time"],"exampleFix":"// before\nconst server = Deno.serveHttp(listener);\n// later: unhandled rejection \"Deno.errors.Http: ...\"\n\n// after\nconst server = Deno.serveHttp(listener);\nserver.finished.catch((err) => {\n  console.error(\"http server failed:\", err?.cause ?? err);\n  Deno.exit(1);\n});","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await server.finished;\n} catch (err) {\n  if (err instanceof Deno.errors.Http) {\n    console.error(\"http server failed:\", err.cause ?? err);\n    Deno.exit(1); // or restart the listener\n  }\n  throw err;\n}","preventionTips":["Never close the raw Deno.Listener/Deno.Conn the server was built on — always go through shutdown() and finished","Always attach a .catch() to server.finished so the rejection is observed, not reported as unhandled later","Log err.cause, not just the wrapped Deno.errors.Http message, to see the real OS-level failure"],"tags":["http","serve","servehttp","shutdown","op-error"],"backgroundTag":"http-server-error","analyzedSha":"abd22074e47c6a5cd14e9e4e84743f084aa5a575","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}