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 leakage #25

Open
sadeghte opened this issue Mar 10, 2023 · 1 comment
Open

Memory leakage #25

sadeghte opened this issue Mar 10, 2023 · 1 comment

Comments

@sadeghte
Copy link

When you run this simple code, memory grows unbounded. In my test it leaked more than 5 GB of memory.

import createKeccakHash from 'keccak'

const hash = msg => {
  return '0x' + createKeccakHash('keccak256').update(msg).digest('hex')
}

const mine = function(seed, difficulty = 5) {
  let nonce = 0;
  difficulty = parseInt(difficulty);
  const prefix = '0x' + new Array(difficulty).fill('0').join('')
  while (true) {
    const h = hash(seed + nonce);
    if (!!h && h.substring(0, difficulty+2) === prefix) {
      return nonce;
    }
    nonce += 1;
  }
}

console.log("running ....")
const seed = "hfjshjdhsjhdjshdjs"
const nonce = mine(seed, 8)
console.log({
  nonce,
})

the createKeccakHash method thakes some memory and not release it.

@ericz
Copy link

ericz commented Mar 22, 2023

I noticed this as well. Seems like a problem specific to the node bindings. When importing keccak/js instead, it did not leak.

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

2 participants