Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clone response backport #71115

Merged
merged 2 commits into from
Oct 10, 2024
Merged

Fix clone response backport #71115

merged 2 commits into from
Oct 10, 2024

Conversation

ijjk
Copy link
Member

@ijjk ijjk commented Oct 10, 2024

Follow-up to #70649 this tweaks the backport to properly clone and return original response so that pending revalidates aren't sharing an already used response.

@ijjk
Copy link
Member Author

ijjk commented Oct 10, 2024

Stats from current PR

Default Build (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js 14-2-1 vercel/next.js ijjk/fix-res-clone-backport Change
buildDuration 16.4s 14.9s N/A
buildDurationCached 7.7s 6.8s N/A
nodeModulesSize 200 MB 200 MB ⚠️ +23.2 kB
nextStartRea..uration (ms) 405ms 405ms
Client Bundles (main, webpack)
vercel/next.js 14-2-1 vercel/next.js ijjk/fix-res-clone-backport Change
1a9f679d-HASH.js gzip 53.7 kB 53.7 kB N/A
5428.HASH.js gzip 181 B 180 B N/A
6067-HASH.js gzip 5.06 kB 5.06 kB N/A
6428-HASH.js gzip 31.6 kB 31.6 kB N/A
framework-HASH.js gzip 44.9 kB 44.9 kB
main-app-HASH.js gzip 241 B 243 B N/A
main-HASH.js gzip 32.3 kB 32.3 kB N/A
webpack-HASH.js gzip 1.68 kB 1.68 kB N/A
Overall change 44.9 kB 44.9 kB
Legacy Client Bundles (polyfills)
vercel/next.js 14-2-1 vercel/next.js ijjk/fix-res-clone-backport Change
polyfills-HASH.js gzip 39.4 kB 39.4 kB
Overall change 39.4 kB 39.4 kB
Client Pages
vercel/next.js 14-2-1 vercel/next.js ijjk/fix-res-clone-backport Change
_app-HASH.js gzip 196 B 196 B
_error-HASH.js gzip 184 B 185 B N/A
amp-HASH.js gzip 502 B 504 B N/A
css-HASH.js gzip 321 B 324 B N/A
dynamic-HASH.js gzip 1.82 kB 1.82 kB N/A
edge-ssr-HASH.js gzip 258 B 257 B N/A
head-HASH.js gzip 352 B 352 B
hooks-HASH.js gzip 371 B 372 B N/A
image-HASH.js gzip 4.23 kB 4.23 kB N/A
index-HASH.js gzip 259 B 257 B N/A
link-HASH.js gzip 2.67 kB 2.68 kB N/A
routerDirect..HASH.js gzip 316 B 314 B N/A
script-HASH.js gzip 385 B 386 B N/A
withRouter-HASH.js gzip 311 B 310 B N/A
1afbb74e6ecf..834.css gzip 106 B 106 B
Overall change 654 B 654 B
Client Build Manifests
vercel/next.js 14-2-1 vercel/next.js ijjk/fix-res-clone-backport Change
_buildManifest.js gzip 483 B 481 B N/A
Overall change 0 B 0 B
Rendered Page Sizes
vercel/next.js 14-2-1 vercel/next.js ijjk/fix-res-clone-backport Change
index.html gzip 529 B 529 B
link.html gzip 542 B 540 B N/A
withRouter.html gzip 523 B 524 B N/A
Overall change 529 B 529 B
Edge SSR bundle Size
vercel/next.js 14-2-1 vercel/next.js ijjk/fix-res-clone-backport Change
edge-ssr.js gzip 95.5 kB 95.5 kB N/A
page.js gzip 3.06 kB 3.06 kB N/A
Overall change 0 B 0 B
Middleware size
vercel/next.js 14-2-1 vercel/next.js ijjk/fix-res-clone-backport Change
middleware-b..fest.js gzip 657 B 659 B N/A
middleware-r..fest.js gzip 156 B 154 B N/A
middleware.js gzip 25.5 kB 25.5 kB
edge-runtime..pack.js gzip 839 B 839 B
Overall change 26.4 kB 26.4 kB
Next Runtimes
vercel/next.js 14-2-1 vercel/next.js ijjk/fix-res-clone-backport Change
app-page-exp...dev.js gzip 171 kB 171 kB
app-page-exp..prod.js gzip 98.3 kB 98.3 kB
app-page-tur..prod.js gzip 100 kB 100 kB
app-page-tur..prod.js gzip 94.3 kB 94.3 kB
app-page.run...dev.js gzip 145 kB 145 kB
app-page.run..prod.js gzip 92.8 kB 92.8 kB
app-route-ex...dev.js gzip 22 kB 22.1 kB N/A
app-route-ex..prod.js gzip 15.5 kB 15.5 kB N/A
app-route-tu..prod.js gzip 15.5 kB 15.5 kB N/A
app-route-tu..prod.js gzip 15.2 kB 15.2 kB N/A
app-route.ru...dev.js gzip 21.7 kB 21.7 kB N/A
app-route.ru..prod.js gzip 15.2 kB 15.2 kB N/A
pages-api-tu..prod.js gzip 9.58 kB 9.58 kB
pages-api.ru...dev.js gzip 9.85 kB 9.85 kB
pages-api.ru..prod.js gzip 9.57 kB 9.57 kB
pages-turbo...prod.js gzip 22.5 kB 22.5 kB
pages.runtim...dev.js gzip 23.2 kB 23.2 kB
pages.runtim..prod.js gzip 22.5 kB 22.5 kB
server.runti..prod.js gzip 51.6 kB 51.6 kB
Overall change 851 kB 851 kB
build cache Overall increase ⚠️
vercel/next.js 14-2-1 vercel/next.js ijjk/fix-res-clone-backport Change
0.pack gzip 1.6 MB 1.6 MB ⚠️ +461 B
index.pack gzip 114 kB 114 kB N/A
Overall change 1.6 MB 1.6 MB ⚠️ +461 B
Diff details
Diff for middleware.js

Diff too large to display

Diff for edge-ssr.js

Diff too large to display

Diff for app-route-ex..ntime.dev.js

Diff too large to display

Diff for app-route-ex..time.prod.js

Diff too large to display

Diff for app-route-tu..time.prod.js

Diff too large to display

Diff for app-route-tu..time.prod.js

Diff too large to display

Diff for app-route.runtime.dev.js

Diff too large to display

Diff for app-route.ru..time.prod.js

Diff too large to display

Commit: aedf05f

@ijjk ijjk merged commit 4f395f5 into 14-2-1 Oct 10, 2024
51 of 56 checks passed
@ijjk ijjk deleted the ijjk/fix-res-clone-backport branch October 10, 2024 18:53
@mogzol
Copy link

mogzol commented Oct 18, 2024

Any updates on when this will be released? Many people are experiencing this issue, see #69635

@ijjk
Copy link
Member Author

ijjk commented Oct 23, 2024

Hi, this is updated in v14.2.16 please update and give it a try!

@hari-menon-bpai
Copy link

Still seeing the issue. Is there a workaround I can use till this is fixed?

@ijjk
Copy link
Member Author

ijjk commented Oct 23, 2024

Can you show the error you are seeing on 14.2.16?

@hari-menon-bpai
Copy link

errors: [
{
code: 'unexpected_error',
message: 'Response.clone: Body has already been consumed.'
}
],

@enzoferey
Copy link
Contributor

@ijjk I can confirm this still happens on 14.2.16 and Node.js 20.x on Vercel. One example of a failed deployment in one of our apps is BRefcnk98VHziVA2mNdBjS5RXdU1.

@hari-menon-bpai
Copy link

Is there a workaround or an older version I can go to before this bug was introduced?

@mogzol
Copy link

mogzol commented Oct 23, 2024

I'm not familiar with the next.js code, but looking at the changes, it seems like maybe the issue is that you are cloning the cloned response and not the original response on line 738, since the pendingRevalidate promise would return the cloned response and not the original one? So if that cloned response is being read somewhere else, it would cause this issue.

EDIT: Never mind, nothing else is done with nextRevalidate so I don't think it would be that.

@enzoferey
Copy link
Contributor

Hey guys, any updates? This is heavily affecting our business.

@stephan-noel
Copy link

I just verified as well, upgraded to 14.2.16 and verified in my lock file. Using 22-alpine on Docker.

TypeError: Response.clone: Body has already been consumed.

Happened when I made about 100 fetch calls in close proximity to each other, but I've observed it happen for around 40 requests in close proximity to each other as well. Batching the calls with a delay in between the batches did help, but I'm worried it could pop up again out of nowhere.

Let me know if there is any other info that might be useful.

@LeoActency
Copy link

LeoActency commented Nov 4, 2024

EDIT : After reading #69635 (reply in thread) we downgraded nodejs from version 20.18 to 20.16 and this fixed the problem for us (node 20.16 + next 14.2.16 = OK).

We also have this problem on our project (version 14.2.5).
After updating to 14.2.16, the problem persists.

Here are a few details about our case, in the hope that this will help to find the cause :

  • The problem only occurs when using draft mode.
  • When building and browsing static pages, there are no errors.
  • It seems to appear more on heavier pages requiring a lot of requests.
  • On these pages, around 4 out of 5 loads end up with this error, while 1 out of 5 loads without error.
TypeError: Response.clone: Body has already been consumed.
    at webidl.errors.exception (node:internal/deps/undici/undici:3384:14)
    at _Response.clone (node:internal/deps/undici/undici:8883:31)
    at /app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:181023
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  digest: '2120061210'
}

@vineethvijayan314
Copy link

Does this issue cause your application to be redirected to your home randomly?

@vboginskey
Copy link

@ijjk heads up: lots of folks still experiencing this issue.

Here is the stack trace on Next v14.2.18 running on node:22.10.0-alpine:

TypeError: Response.clone: Body has already been consumed.
  File "node:internal/deps/undici/undici", line 3564, col 14, in webidl.errors.exception
  File "node:internal/deps/undici/undici", line 9081, col 31, in _Response.clone
  File "/app/node_modules/.pnpm/next@14.2.18_@babel+core@7.24.4_@opentelemetry+api@1.9.0_@playwright+test@1.48.2_react-dom@18_uiv6pxahu6syeertjd5vuf2z6e/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js", line 12, col 181023
  File "node:internal/process/task_queues", line 105, col 5, in process.processTicksAndRejections

@ijjk
Copy link
Member Author

ijjk commented Dec 4, 2024

This investigation is being continued in #73274

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants