Fix prerender manifest update race in dev (#100521)
in dev, we update the prerender manifest based on the
`generateStaticParams` result. we were using
`fs.promises.{readFile,writeFile}` for this, which made it possible for
parallel requests to interfere with each other -- when a file is opened
for writing by `fs.promises.writeFile`, it gets truncated, and if
another request tries to read the manifest in the meantime, it can
observe an empty file. this [has caused intermittent
crashes](https://app.datadoghq.com/ci/ci-cd/explorer/executions?query=test_level%3Atest%20%40git.repository.id%3A%22github.com%2Fvercel%2Fnext.js%22%20%40test.name%3A%22use-cache-fallback-root-params%20resolves%20cached%20and%20uncached%20roots%20on%20ordinary%20requests%22%20%40test.status%3A%22fail%22&agg_m=count&agg_m_source=base&agg_t=count&ci_cd_explorer_tab=tests¤tTab=overview&eventStack=&fromUser=true&start=1789839150900&end=1792431150900&paused=false)
in `use-cache-fallback-root-params > resolves cached and uncached roots
on ordinary requests` which has a couple requests hitting the same route
in parallel with different params and attempting to update the manifest.
switching the reads/writes to be synchronous avoids this problem. i was
unable to reproduce this race in 100 runs of
`use-cache-fallback-root-params`, which previously would get a failure
in around 20 runs
Showing
Please
register
or
sign in
to comment