oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
71.82k stars 2.55k forks source link

possible memory leak in Bun.password.hash #5296

Open NFTBattle opened 9 months ago

NFTBattle commented 9 months ago

What version of Bun is running?

1.0

What platform is your computer?

Linux 6.2.0-32-generic x86_64 x86_64

What steps can reproduce the bug?

When I run this code, it will keep eating up memory until the os crashes.


  function generateRandomSha256(maxLength = 128) {
      const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
      const randomString = [...Array(maxLength)].map(() => characters.charAt(Math.floor(Math.random() * characters.length))).join('');
      const hasher = new Bun.CryptoHasher("sha256");
      hasher.update(randomString);
      return hasher.digest();
  }

    while (true) {

        let randomData = generateRandomSha256();      
        const hashedData = await Bun.password.hash(randomData , {
            algorithm: "argon2id",
            memoryCost: 120,
            timeCost: 1,
            salt: "THIS-CAUSES-MEMORY-LEAK"
        });

        console.log(hashedData);

    }

What is the expected behavior?

garbage cleanup should keep memory in check, nothing about this code should keep taking up more memory.

What do you see instead?

memory keeps going up until os crashes

Additional information

No response

nektro commented 1 month ago

is this still impacting you? tried this on Bun 1.1.9 and am not seeing any discernible rise in ram usage anymore on my end.