TanStack / TanStack/router

DOMException: The connection was closed is not catchable

Open
#6,069 1 comment 10 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
15.1k
Forks
1.9k
Avg merge
1d 20h
Merged PRs (30d)
143

Description

Which project does this relate to?

Start

Describe the bug

When a client disconnects during streaming, the resulting DOMException: The connection was closed cannot be caught and floods the production server logs.

This issue often arises from bots or users closing the tab while streaming is still in progress.

Your Example Website or App

https://github.com/checkerschaf/start-domexception-aborterror

Steps to Reproduce the Bug or Issue
  1. Clone the reproduction repo
  2. Run bun install
  3. Run bun run build
  4. Start the server: bun run bun-server.ts
  5. Run the script bun run reproduce-abort-error.ts in a new terminal while the server is running
Expected behavior

No errors in the server console and the streaming cancellation should be handled gracefully.

Screenshots or Videos

No response

Platform
  • Start Version: 1.140.5
  • Bun: 1.3.4
Additional context

Full error logs:

error: The connection was closed.
      cause: DOMException {
  line: 4174,
  column: 32,
  sourceURL: "/Users/xyz/tart-domexception-aborterror/node_modules/react-dom/cjs/react-dom-server.bun.production.js",
  stack: "@/Users/xyz/tart-domexception-aborterror/node_modules/react-dom/cjs/react-dom-server.bun.production.js:4174:32\nPromise@\n@/Users/xyz/tart-domexception-aborterror/node_modules/react-dom/cjs/react-dom-server.bun.production.js:4137:23\n@/Users/xyz/tart-domexception-aborterror/node_modules/@tanstack/react-router/dist/esm/ssr/renderRouterToStream.js:12:63\nrenderRouterToStream@/Users/xyz/tart-domexception-aborterror/node_modules/@tanstack/react-router/dist/esm/ssr/renderRouterToStream.js:5:37\n@/Users/xyz/tart-domexception-aborterror/dist/server/server.js:315:32\nprocessTicksAndRejections@",
  code: 20,
  name: "AbortError",
  message: "The connection was closed.",
  INDEX_SIZE_ERR: 1,
  DOMSTRING_SIZE_ERR: 2,
  HIERARCHY_REQUEST_ERR: 3,
  WRONG_DOCUMENT_ERR: 4,
  INVALID_CHARACTER_ERR: 5,
  NO_DATA_ALLOWED_ERR: 6,
  NO_MODIFICATION_ALLOWED_ERR: 7,
  NOT_FOUND_ERR: 8,
  NOT_SUPPORTED_ERR: 9,
  INUSE_ATTRIBUTE_ERR: 10,
  INVALID_STATE_ERR: 11,
  SYNTAX_ERR: 12,
  INVALID_MODIFICATION_ERR: 13,
  NAMESPACE_ERR: 14,
  INVALID_ACCESS_ERR: 15,
  VALIDATION_ERR: 16,
  TYPE_MISMATCH_ERR: 17,
  SECURITY_ERR: 18,
  NETWORK_ERR: 19,
  ABORT_ERR: 20,
  URL_MISMATCH_ERR: 21,
  QUOTA_EXCEEDED_ERR: 22,
  TIMEOUT_ERR: 23,
  INVALID_NODE_TYPE_ERR: 24,
  DATA_CLONE_ERR: 25,
  toString: [Function: toString],
},
     status: 500,
 statusText: undefined,
    headers: undefined,
       data: undefined,
       body: undefined,
  unhandled: true,

      at /Users/xyz/tart-domexception-aborterror/node_modules/h3-v2/dist/h3.mjs:315:41

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked reproduction repo and run bun install, bun run build, bun run bun-server.ts, then reproduce-abort-error.ts. Trace the server-side streaming path shown in the stack, including renderRouterToStream and h3-v2 handling, and rerun the reproduction; done means client disconnects are cancelled gracefully without flooding the server console with errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
bun, react, typescript
Domain
backend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.