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

Memory leak with deno/bun when catching errors #633

Open
daweijs opened this issue Sep 12, 2024 · 0 comments
Open

Memory leak with deno/bun when catching errors #633

daweijs opened this issue Sep 12, 2024 · 0 comments

Comments

@daweijs
Copy link

daweijs commented Sep 12, 2024

Reproduction with deno :

ky.deno.test.ts :

import ky from "https://esm.sh/[email protected]";

Deno.test("throws HTTPError : no memory leak", async () => {
  // this test throws the expected error and does not leak memory
  // HTTPError: Request failed with status code 404 Not Found: GET https://github.com/not_found

  await ky.get("https://github.com/not_found").text();
});

Deno.test("memory leak when catching error", async () => {
  // this test report a memory leak when catching the error
  // the memory leak is fixed if we rethrow something

  // the test fails with :
  // Leaks detected:
  // - A fetch response body was created during the test, but not consumed during the test. Consume or close the response body `ReadableStream`, e.g `await resp.text()` or `await resp.body.cancel()`.

  try {
    await ky.get("https://github.com/not_found").text();
  } catch (error) {
    console.error("I handle the error here");

    // fix the leak : rethrow the error
    // throw error;
  }
});

deno test --allow-net ky.deno.test.ts

Same issue with bun : denoland/deno#25546 (comment)

@daweijs daweijs changed the title Memory leak with deno/bun Memory leak with deno/bun when catching errors Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant