-
-
Notifications
You must be signed in to change notification settings - Fork 365
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
A ReadableStream branch was created but never consumed #648
Comments
PR welcome to fix this issue. If I'm not mistaken, canceling the stream could lead to lost data even though we've cloned the stream. We'd need to test it thoroughly to make sure that's not the case. |
Clean up orphan ReadableStream remaining during parsing response (sindresorhus#648)
I‘m willing to do so, and a PR have already been submitted . export default {
async fetch (): Promise<Response> {
const originalResponse = new Response("Some Data");
const clonedResponse = originalResponse.clone();
await originalResponse.body?.cancel();
console.log("Original Stream Data:", await originalResponse.body?.getReader().read());
console.log("Cloned Stream Data:", await clonedResponse.body?.getReader().read());
return new Response("");
}
} satisfies ExportedHandler; I cloned an unconsumed response and canceled the The result is as follows:
The original ReadableStream has already been canceled, but the cloned response has an independent ReadableStream object that can be consumed. |
There is also a similar issue about orphan ReadableStream remaining. Related to :#650 |
I'm not sure if this applies to Cloudflare Workers, but the undici team released version |
Fixes sindresorhus#648 This removes an unnecessary response clone that was used in body method shortcuts, such as `ky().json()`, which caused the original response to be fully buffered and never consumed.
#661 might not have fixed this. I'm on v1.7.4 and getting this error const response = await ky.post("...url...", {
throwHttpErrors: false,
retry: { limit: 0 },
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${ctx.env.API_KEY}`,
},
json: <...data...>,
})
if (!response.ok) {
console.error(response.statusText)
return
}
const jsonResponse = await response.json()
|
@work-in-progress-danny you are probably encountering #650, which is technically a separate but similar problem that leads to the same outcome. Think of it as a "Part 2", if you will. There is already a PR to fix it, see #651. I was hoping to release these together but something has been causing CI to fail on that PR and I'm not sure why yet. It passes locally for me. The failure might be related to usage of httpbin.org in the tests, which would make it unrelated to that PR, but that's just a guess. Once that is solved, we'll get that PR merged and released quickly. Feel free to help investigate the CI failure if you have time. |
Awesome, thanks so much @sholladay! Love this package 🙏 |
I'm using ky in cloudflare worker with following code:
and when I turn off local mode, requests raise the following warning:
Locate the following code snippet:
source/core/Ky.ts
The
awaitedResult
is a variable of type Response. Since it is declared, it has been cloned only once, and its ReadableStream has never been consumed.After
awaitedResult
has finished cloning, its ReadableStream should be closed to ensure memory safety.Seems like:
The text was updated successfully, but these errors were encountered: