nextjs network_error ai_generated true

错误:操作已中止。(边缘运行时:由于超时或取消而中止的 fetch)

Error: The operation was aborted. (Edge Runtime: fetch aborted due to timeout or cancellation)

ID: nextjs/edge-runtime-fetch-abort

其他格式: JSON · Markdown 中文 · English
80%修复率
83%置信度
1证据数
2024-01-10首次发现

版本兼容性

版本状态引入弃用备注
Next.js 13.x active
Next.js 14.x active
Next.js 15.x active
Edge Runtime (Vercel) active

根因分析

在边缘运行时(例如中间件、边缘 API 路由)中,fetch 请求默认超时为 30 秒,如果响应太慢或客户端断开连接,运行时可能会中止请求。

English

In the Edge Runtime (e.g., middleware, edge API routes), fetch requests have a default timeout of 30 seconds and can be aborted by the runtime if the response is too slow or if the client disconnects.

generic

官方文档

https://nextjs.org/docs/app/api-reference/edge

解决方案

  1. Optimize the external API response time (e.g., use caching, reduce payload size) to ensure it completes within 30 seconds. Alternatively, use a server-side data fetching pattern with incremental static regeneration (ISR) to avoid real-time fetch.
  2. Move the fetch to a server component (Node.js runtime) where there is no 30-second timeout limit. Use the edge runtime only for lightweight operations.

无效尝试

常见但无效的做法:

  1. 80% 失败

    The Edge Runtime has a hard limit of 30 seconds for fetch; this cannot be overridden. The config option may not exist or be ignored in edge.

  2. 70% 失败

    The runtime will still abort at 30 seconds even if the AbortController signal is set to a longer timeout.

  3. 50% 失败

    If the route is already on edge, the runtime is fixed; moving to Node.js may require other changes (e.g., removing edge-specific APIs).