Unverified Commit 94bda499 authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

fix fetch lock not being consistently released (#74623)

When we acquire a lock on a fetch, and the fetch errors, we weren't
resolving the lock. This meant a subsequent request would stall waiting
to acquire a lock and prevent the page from rendering.

An example of this is a fetch with force-cache in `generateMetadata` and
another in the RSC where both requests encounter a fetch error.

Fixes #74613
parent 832c77d0
......@@ -610,7 +610,8 @@ export function createPatchedFetcher(
next: { ...init?.next, fetchType: 'origin', fetchIdx },
}
return originFetch(input, clonedInit).then(async (res) => {
return originFetch(input, clonedInit)
.then(async (res) => {
if (!isStale && fetchStart) {
trackFetchMetric(workStore, {
start: fetchStart,
......@@ -629,7 +630,8 @@ export function createPatchedFetcher(
res.status === 200 &&
incrementalCache &&
cacheKey &&
(isCacheableRevalidate || requestStore?.serverComponentsHmrCache)
(isCacheableRevalidate ||
requestStore?.serverComponentsHmrCache)
) {
const normalizedRevalidate =
finalRevalidate >= INFINITE_CACHE
......@@ -681,6 +683,7 @@ export function createPatchedFetcher(
// exists a bug in the undici library around response cloning.
// See the following pull request for more details:
// https://github.com/vercel/next.js/pull/73274
const [cloned1, cloned2] = cloneResponse(res)
// We are dynamically rendering including dev mode. We want to return
......@@ -736,6 +739,10 @@ export function createPatchedFetcher(
return res
})
.catch((error) => {
handleUnlock()
throw error
})
}
let cacheReasonOverride
......
import { nextTestSetup } from 'e2e-utils'
describe('app-fetch-errors', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('should still successfully render when a fetch request that acquires a cache lock errors', async () => {
const browser = await next.browser('/1')
expect(await browser.elementByCss('body').text()).toBe('Hello World 1')
})
})
'use server'
import { Metadata } from 'next'
export async function generateMetadata({
params,
}: {
params: Promise<{ id: string }>
}): Promise<Metadata> {
const { id } = await params
try {
// this fetch request will error
await fetch('http://localhost:8000', {
cache: 'force-cache',
next: { tags: ['id'] },
})
} catch (err) {
console.log(err)
}
return {
title: id,
}
}
export default async function Error({
params,
}: {
params: Promise<{ id: string }>
}) {
const { id } = await params
try {
// this fetch request will error
await fetch('http://localhost:8000', {
cache: 'force-cache',
next: { tags: ['id'] },
})
} catch (err) {
console.log(err)
}
return <div>Hello World {id}</div>
}
export default function Layout({ children }) {
return (
<html lang="en">
<head>
<title>my static site</title>
</head>
<body>{children}</body>
</html>
)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment