nextjs - ✅(Solved) Fix Aborted requests cause middleware to crash in development [1 pull requests, 7 comments, 5 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#84649Fetched 2026-04-08 02:18:53
View on GitHub
Comments
7
Participants
5
Timeline
29
Reactions
4
Timeline (top)
subscribed ×8commented ×7mentioned ×5labeled ×4

Error Message

Error: aborted at connResetException (node:internal/errors:721:14) at abortIncoming (node:_http_server:793:17) at socketOnClose (node:_http_server:787:3) at Socket.emit (node:events:526:35) at TCP.<anonymous> (node:net:337:12) at TCP.callbackTrampoline (node:internal/async_hooks:130:17) Emitted 'error' event on IncomingMessage instance at: at emitErrorNT (node:internal/streams/destroy:151:8) at emitErrorCloseNT (node:internal/streams/destroy:116:3) at process.processTicksAndRejections (node:internal/process/task_queues:82:21) { code: 'ECONNRESET' }

Fix Action

Fixed

PR fix notes

PR #67: refactor: migrate web app from Next.js to TanStack Start

Description (problem / solution / changelog)

Summary

  • Migrates apps/web/ from Next.js App Router to TanStack Start, resolving the dev server crash caused by vercel/next.js#84649 where aborted Convex real-time subscriptions crash the dev server when middleware is present
  • Replaces entire build/routing/auth stack: Next.js → Vite/Nitro, App Router → TanStack Router file routes, convexBetterAuthNextJsconvexBetterAuthReactStart, NEXT_PUBLIC_*VITE_*
  • Adopts TanStack Start idioms: beforeLoad auth guards, route context for session sharing, Link activeProps, per-page head() titles, errorComponent/notFoundComponent, pendingComponent

What changed

Build & config

  • next.config.tsvite.config.ts (TanStack Start + Vite + React Compiler)
  • @t3-oss/env-nextjs@t3-oss/env-core with VITE_ prefix
  • Turborepo outputs: .next/**.output/**
  • CI workflow env vars updated to VITE_*

Routing (7 pages migrated)

  • src/app/ (Next.js App Router) → src/routes/ (TanStack Router file routes)
  • Auth guard via pathless _authenticated.tsx layout with beforeLoad
  • Root route shares session token via context (no redundant server calls)
  • Type-safe Link with to/params, validateSearch for search params

Auth

  • convexBetterAuthNextJsconvexBetterAuthReactStart
  • Server-side session check via createServerFn
  • Signin page uses beforeLoad redirect (not client-side useEffect)

Components

  • All next/link@tanstack/react-router Link (10 files)
  • All next/navigation hooks → TanStack Router equivalents (6 files)
  • All "use client" directives removed
  • Header uses Link activeProps instead of manual pathname matching
  • Upload page split from 510-line monolith into thin route + 3 extracted tab components
  • Toast links use <a> instead of <Link> (portal context safety)

E2E tests

  • Added waitForLoadState("networkidle") after all page.goto() calls for SSR hydration
  • Fixed source-provenance test to wait for detail page render
  • 61/64 tests pass (3 remaining are pre-existing flakes unrelated to migration)

Cleanup

  • Deleted entire src/app/ directory, next.config.ts, postcss.config.mjs, next-env.d.ts
  • Removed next-best-practices and vercel-react-best-practices skills
  • Removed unused @tailwindcss/postcss dependency
  • Cleaned stale .vinxi/.react-router from gitignore/tsconfig
  • Updated AGENTS.md tech stack reference

Test plan

  • bunx tsc --noEmit passes with zero errors
  • Dev server starts on port 3001 (~1s startup)
  • Auth flow works (sign up, sign in, sign out)
  • 61/64 E2E tests pass (3 flaky tests unrelated to migration)
  • Zero next/ imports remain in apps/web/src/
  • Zero "use client" directives remain
  • CI workflow uses VITE_* env vars
  • Verify CI pipeline passes end-to-end

Changed files

  • .agents/skills/next-best-practices/SKILL.md (removed, +0/-171)
  • .agents/skills/next-best-practices/async-patterns.md (removed, +0/-84)
  • .agents/skills/next-best-practices/bundling.md (removed, +0/-182)
  • .agents/skills/next-best-practices/data-patterns.md (removed, +0/-300)
  • .agents/skills/next-best-practices/debug-tricks.md (removed, +0/-122)
  • .agents/skills/next-best-practices/directives.md (removed, +0/-74)
  • .agents/skills/next-best-practices/error-handling.md (removed, +0/-228)
  • .agents/skills/next-best-practices/file-conventions.md (removed, +0/-141)
  • .agents/skills/next-best-practices/font.md (removed, +0/-246)
  • .agents/skills/next-best-practices/functions.md (removed, +0/-108)
  • .agents/skills/next-best-practices/hydration-error.md (removed, +0/-86)
  • .agents/skills/next-best-practices/image.md (removed, +0/-173)
  • .agents/skills/next-best-practices/metadata.md (removed, +0/-292)
  • .agents/skills/next-best-practices/parallel-routes.md (removed, +0/-286)
  • .agents/skills/next-best-practices/route-handlers.md (removed, +0/-143)
  • .agents/skills/next-best-practices/rsc-boundaries.md (removed, +0/-160)
  • .agents/skills/next-best-practices/runtime-selection.md (removed, +0/-40)
  • .agents/skills/next-best-practices/scripts.md (removed, +0/-137)
  • .agents/skills/next-best-practices/self-hosting.md (removed, +0/-375)
  • .agents/skills/next-best-practices/suspense-boundaries.md (removed, +0/-67)
  • .agents/skills/vercel-react-best-practices/AGENTS.md (removed, +0/-2924)
  • .agents/skills/vercel-react-best-practices/README.md (removed, +0/-127)
  • .agents/skills/vercel-react-best-practices/SKILL.md (removed, +0/-139)
  • .agents/skills/vercel-react-best-practices/rules/advanced-event-handler-refs.md (removed, +0/-55)
  • .agents/skills/vercel-react-best-practices/rules/advanced-init-once.md (removed, +0/-42)
  • .agents/skills/vercel-react-best-practices/rules/advanced-use-latest.md (removed, +0/-39)
  • .agents/skills/vercel-react-best-practices/rules/async-api-routes.md (removed, +0/-35)
  • .agents/skills/vercel-react-best-practices/rules/async-defer-await.md (removed, +0/-80)
  • .agents/skills/vercel-react-best-practices/rules/async-dependencies.md (removed, +0/-48)
  • .agents/skills/vercel-react-best-practices/rules/async-parallel.md (removed, +0/-24)
  • .agents/skills/vercel-react-best-practices/rules/async-suspense-boundaries.md (removed, +0/-99)
  • .agents/skills/vercel-react-best-practices/rules/bundle-barrel-imports.md (removed, +0/-59)
  • .agents/skills/vercel-react-best-practices/rules/bundle-conditional.md (removed, +0/-37)
  • .agents/skills/vercel-react-best-practices/rules/bundle-defer-third-party.md (removed, +0/-48)
  • .agents/skills/vercel-react-best-practices/rules/bundle-dynamic-imports.md (removed, +0/-34)
  • .agents/skills/vercel-react-best-practices/rules/bundle-preload.md (removed, +0/-44)
  • .agents/skills/vercel-react-best-practices/rules/client-event-listeners.md (removed, +0/-78)
  • .agents/skills/vercel-react-best-practices/rules/client-localstorage-schema.md (removed, +0/-74)
  • .agents/skills/vercel-react-best-practices/rules/client-passive-event-listeners.md (removed, +0/-48)
  • .agents/skills/vercel-react-best-practices/rules/client-swr-dedup.md (removed, +0/-56)
  • .agents/skills/vercel-react-best-practices/rules/js-batch-dom-css.md (removed, +0/-110)
  • .agents/skills/vercel-react-best-practices/rules/js-cache-function-results.md (removed, +0/-80)
  • .agents/skills/vercel-react-best-practices/rules/js-cache-property-access.md (removed, +0/-28)
  • .agents/skills/vercel-react-best-practices/rules/js-cache-storage.md (removed, +0/-68)
  • .agents/skills/vercel-react-best-practices/rules/js-combine-iterations.md (removed, +0/-32)
  • .agents/skills/vercel-react-best-practices/rules/js-early-exit.md (removed, +0/-50)
  • .agents/skills/vercel-react-best-practices/rules/js-hoist-regexp.md (removed, +0/-45)
  • .agents/skills/vercel-react-best-practices/rules/js-index-maps.md (removed, +0/-37)
  • .agents/skills/vercel-react-best-practices/rules/js-length-check-first.md (removed, +0/-50)
  • .agents/skills/vercel-react-best-practices/rules/js-min-max-loop.md (removed, +0/-82)
  • .agents/skills/vercel-react-best-practices/rules/js-set-map-lookups.md (removed, +0/-24)
  • .agents/skills/vercel-react-best-practices/rules/js-tosorted-immutable.md (removed, +0/-57)
  • .agents/skills/vercel-react-best-practices/rules/rendering-activity.md (removed, +0/-26)
  • .agents/skills/vercel-react-best-practices/rules/rendering-animate-svg-wrapper.md (removed, +0/-38)
  • .agents/skills/vercel-react-best-practices/rules/rendering-conditional-render.md (removed, +0/-32)
  • .agents/skills/vercel-react-best-practices/rules/rendering-content-visibility.md (removed, +0/-38)
  • .agents/skills/vercel-react-best-practices/rules/rendering-hoist-jsx.md (removed, +0/-36)
  • .agents/skills/vercel-react-best-practices/rules/rendering-hydration-no-flicker.md (removed, +0/-72)
  • .agents/skills/vercel-react-best-practices/rules/rendering-hydration-suppress-warning.md (removed, +0/-26)
  • .agents/skills/vercel-react-best-practices/rules/rendering-svg-precision.md (removed, +0/-28)
  • .agents/skills/vercel-react-best-practices/rules/rendering-usetransition-loading.md (removed, +0/-75)
  • .agents/skills/vercel-react-best-practices/rules/rerender-defer-reads.md (removed, +0/-39)
  • .agents/skills/vercel-react-best-practices/rules/rerender-dependencies.md (removed, +0/-45)
  • .agents/skills/vercel-react-best-practices/rules/rerender-derived-state-no-effect.md (removed, +0/-40)
  • .agents/skills/vercel-react-best-practices/rules/rerender-derived-state.md (removed, +0/-29)
  • .agents/skills/vercel-react-best-practices/rules/rerender-functional-setstate.md (removed, +0/-77)
  • .agents/skills/vercel-react-best-practices/rules/rerender-lazy-state-init.md (removed, +0/-56)
  • .agents/skills/vercel-react-best-practices/rules/rerender-memo-with-default-value.md (removed, +0/-36)
  • .agents/skills/vercel-react-best-practices/rules/rerender-memo.md (removed, +0/-44)
  • .agents/skills/vercel-react-best-practices/rules/rerender-move-effect-to-event.md (removed, +0/-45)
  • .agents/skills/vercel-react-best-practices/rules/rerender-simple-expression-in-memo.md (removed, +0/-35)
  • .agents/skills/vercel-react-best-practices/rules/rerender-transitions.md (removed, +0/-40)
  • .agents/skills/vercel-react-best-practices/rules/rerender-use-ref-transient-values.md (removed, +0/-73)
  • .agents/skills/vercel-react-best-practices/rules/server-after-nonblocking.md (removed, +0/-73)
  • .agents/skills/vercel-react-best-practices/rules/server-auth-actions.md (removed, +0/-96)
  • .agents/skills/vercel-react-best-practices/rules/server-cache-lru.md (removed, +0/-41)
  • .agents/skills/vercel-react-best-practices/rules/server-cache-react.md (removed, +0/-76)
  • .agents/skills/vercel-react-best-practices/rules/server-dedup-props.md (removed, +0/-65)
  • .agents/skills/vercel-react-best-practices/rules/server-hoist-static-io.md (removed, +0/-136)
  • .agents/skills/vercel-react-best-practices/rules/server-parallel-fetching.md (removed, +0/-83)
  • .agents/skills/vercel-react-best-practices/rules/server-serialization.md (removed, +0/-38)
  • .claude/skills/next-best-practices (removed, +0/-1)
  • .claude/skills/vercel-react-best-practices (removed, +0/-1)
  • .github/workflows/ci.yml (modified, +28/-13)
  • .gitignore (modified, +1/-0)
  • .oxlintrc.json (modified, +14/-1)
  • AGENTS.md (modified, +1/-1)
  • apps/e2e/AGENTS.md (modified, +11/-6)
  • apps/e2e/package.json (modified, +1/-0)
  • apps/e2e/playwright.config.ts (modified, +10/-12)
  • apps/e2e/tests/feed-interactions.spec.ts (modified, +10/-10)
  • apps/e2e/tests/global-setup.ts (modified, +6/-35)
  • apps/e2e/tests/helpers.ts (modified, +91/-24)
  • apps/e2e/tests/multi-type-cards.spec.ts (modified, +110/-128)
  • apps/e2e/tests/source-provenance.spec.ts (modified, +9/-31)
  • apps/e2e/tests/tagging.spec.ts (modified, +68/-50)
  • apps/e2e/tests/upload-and-library.spec.ts (modified, +16/-3)
  • apps/e2e/tests/url-ingestion.slow.spec.ts (modified, +16/-6)
  • apps/e2e/tests/url-ingestion.spec.ts (modified, +84/-30)
  • apps/web/.gitignore (modified, +0/-7)

Code Example

Error: aborted
    at connResetException (node:internal/errors:721:14)
    at abortIncoming (node:_http_server:793:17)
    at socketOnClose (node:_http_server:787:3)
    at Socket.emit (node:events:526:35)
    at TCP.<anonymous> (node:net:337:12)
    at TCP.callbackTrampoline (node:internal/async_hooks:130:17)
Emitted 'error' event on IncomingMessage instance at:
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  code: 'ECONNRESET'
}

---

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Sun Aug  6 20:05:33 UTC 2023
  Available memory (MB): 4102
  Available CPU cores: 2
Binaries:
  Node: 20.9.0
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: 8.10.2
Relevant Packages:
  next: 15.6.0-canary.53 // Latest available version is detected (15.6.0-canary.53).
  eslint-config-next: N/A
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.1.3
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/naughty-bush-mcnl34

To Reproduce

  1. Start the "dev" task
  2. Run "npm run repro" in another terminal window, which will make an API request and abort it early
  3. Observe the uncaught exception logged

Current vs. Expected behavior

Current behavior is an uncaughtException is logged, which some applications may handle by shutting down the process (nextjs seems to suppress this by default though)

The full stack trace I noticed when re-throwing the error is:

Error: aborted
    at connResetException (node:internal/errors:721:14)
    at abortIncoming (node:_http_server:793:17)
    at socketOnClose (node:_http_server:787:3)
    at Socket.emit (node:events:526:35)
    at TCP.<anonymous> (node:net:337:12)
    at TCP.callbackTrampoline (node:internal/async_hooks:130:17)
Emitted 'error' event on IncomingMessage instance at:
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  code: 'ECONNRESET'
}

Note that if the (no-op) "middleware.ts" file is deleted, the expected behavior occurs: there is no uncaught exception.

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Sun Aug  6 20:05:33 UTC 2023
  Available memory (MB): 4102
  Available CPU cores: 2
Binaries:
  Node: 20.9.0
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: 8.10.2
Relevant Packages:
  next: 15.6.0-canary.53 // Latest available version is detected (15.6.0-canary.53).
  eslint-config-next: N/A
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.1.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Turbopack, Webpack, Route Handlers, Error Handling, Middleware

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

I've reproed this with/without turbopack, though I've found it much easier / more consistent to repro with turbopack, so that's the repro I'm sharing. I also noticed in my actual application a "unhandledRejection" scenario if the request was aborted without writing the full bytes of the "body", but was focused on the "uncaughtException" case for now, which repros when the full body is sent (then the connection is aborted).

Note that this issue only reproduces during the initial compilation of a route, but it still occurs very frequently in my project. This is due to https://github.com/vercel/next.js/issues/45204, and the fact the graphql requests are often aborted by graphql clients during navigations. This means that many page navigations cause /api/graphql to be recompiled, and if any requests are aborted around that time, it can lead to the server crashing.

See old related issues that never had a full resolution:

I've created a new issue with a clear reproduction with no custom server to demonstrate the issue better

extent analysis

TL;DR

The issue can be mitigated by properly handling the error event on the IncomingMessage instance to prevent uncaught exceptions when requests are aborted.

Guidance

  • Investigate the middleware.ts file to understand its role in the request abortion process and how its removal affects the behavior.
  • Consider adding an error handler for the IncomingMessage instance to catch and handle the error event, potentially preventing the uncaught exception.
  • Review the related issues (e.g., https://github.com/vercel/next.js/issues/45204) to understand the context and potential workarounds for the frequent recompilation of routes.
  • Look into the GraphQL client configuration to see if there are settings that can reduce the frequency of aborted requests.

Example

// Example of handling the error event on the IncomingMessage instance
req.on('error', (err) => {
  // Handle the error, e.g., log it or send a response
  console.error('Error on incoming message:', err);
});

Notes

The provided reproduction case uses Turbopack, but the issue can also occur without it. The frequency of the issue is increased due to the frequent recompilation of routes, which is related to other known issues in Next.js.

Recommendation

Apply a workaround by handling the error event on the IncomingMessage instance to prevent uncaught exceptions when requests are aborted. This approach can help mitigate the issue until a more permanent fix is available.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING