Caching POST requests works but shows warning in console

I'm using this guide to add caching of POST requests to my cloudflare worker: https://developers.cloudflare.com/workers/examples/cache-post-request/ It seems to work, but it's showing warnings in console. For the line that corresponds to const body = await request.clone().text();, it's showing the following error:
A ReadableStream branch was created but never consumed. Such branches can be created, for instance, by calling the tee() method on a ReadableStream, or by calling the clone() method on a Request or Response object. If a branch is created but never consumed, it can force the runtime to buffer the entire body of the stream in memory, which may cause the Worker to exceed its memory limit and be terminated. To avoid this, ensure that all branches created are consumed.

* Unused stream created
A ReadableStream branch was created but never consumed. Such branches can be created, for instance, by calling the tee() method on a ReadableStream, or by calling the clone() method on a Request or Response object. If a branch is created but never consumed, it can force the runtime to buffer the entire body of the stream in memory, which may cause the Worker to exceed its memory limit and be terminated. To avoid this, ensure that all branches created are consumed.

* Unused stream created
Anyone know how to get rid of this warning?
Cloudflare Docs
Cache POST requests Ā· Cloudflare Workers docs
Documentation for Cloudflare Workers, a serverless execution environment that allows you to create entirely new applications or augment existing ones ā€¦
5 Replies
DaniFoldi
DaniFoldiā€¢9mo ago
Hi :meowwave: do you do something with the uncloned request? This warning comes up when you clone a request/response but don't simultaneously drain both bodies
Razzmatazz
RazzmatazzOPā€¢9mo ago
Hi! Yes, the original (uncloned) request is later accessed with await request.json();
DaniFoldi
DaniFoldiā€¢9mo ago
Hmm, the only time I was able to reproduce is when I didn't read one of the two, or read them strictly one after another
Razzmatazz
RazzmatazzOPā€¢9mo ago
ah so if there's a slight delay in reading one of them the warning may be shown? is it safe to ignore the warning if I'm sure both are being read?
Cole-kun
Cole-kunā€¢6mo ago
That's... interesting. I'm facing the same issue, now. šŸ¤”
let newResponse = new Response(response.clone(), response.headers );
context.waitUntil(cache.put(cacheKey, newResponse));

console.log(`newResponse Body Used: ${newResponse.bodyUsed}`)
return response;
let newResponse = new Response(response.clone(), response.headers );
context.waitUntil(cache.put(cacheKey, newResponse));

console.log(`newResponse Body Used: ${newResponse.bodyUsed}`)
return response;
---- [wrangler:inf] GET / 200 OK (1249ms) newResponse Body Used: true A ReadableStream branch was created but never consumed. Such branches can be created, for instance, by calling the tee() method on a ReadableStream, or by calling the clone() method on a Request or Response object. If a branch is created but never consumed, it can force the runtime to buffer the entire body of the stream in memory, which may cause the Worker to exceed its memory limit and be terminated. To avoid this, ensure that all branches created are consumed. šŸ˜•
Want results from more Discord servers?
Add your server