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 in web3.eth.Contract #5704

Closed
2 tasks done
Adeel-trimulabs opened this issue Dec 13, 2022 · 1 comment
Closed
2 tasks done

Memory leak in web3.eth.Contract #5704

Adeel-trimulabs opened this issue Dec 13, 2022 · 1 comment
Assignees
Labels
1.x 1.0 related issues 4.x 4.0 related Estimate Investigate

Comments

@Adeel-trimulabs
Copy link

This is not a Bug Report, Feature Request, or related to Documentation

  • I have searched the existing issues

Is there an existing issue for this?

  • I have searched the existing issues

What's up?

I have made a fully synced ethereum node using binaries (heimdall and bor) and use its RPC point to get blockchain's data. When i start processing blocks, after some time the heap is out of memory. Upon investigating I got to know that this issue is because of web3.eth.Contract.

Environment

Operating system: Mac
bor version: v0.2.16
heimdall version: v0.2.11
web3-eth-contract : v1.8.1

Steps to reproduce

You can run the following sample code with

const Contract = require("web3-eth-contract");
export const getContract = (tokenAddress: string) => {
  Contract.setProvider(web3.currentProvider);
  const contract = new Contract([],'0xc14ca0805194dc4a1319dcad80352d8033763b92');
  return contract;
};

Examples/References

I have tried different approaches specially from these two links #3042 #3866 but my issue persists

@avkos avkos added 1.x 1.0 related issues 4.x 4.0 related Investigate labels Jan 3, 2023
@avkos
Copy link
Contributor

avkos commented Jan 3, 2023

Checked with 1.x and 4.x version this code:

const Web3 = require('web3')

async function main() {
  const web3 = new Web3(new Web3.providers.HttpProvider('https://mainnet.infura.io'))

  for (let i = 0; ;i++) {
    new web3.eth.Contract([], '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2')
    if ((i % 1000) === 0) {
      // Use node --expose-gc ./testLeak.js
      if (global.gc) { global.gc() }
      const used = process.memoryUsage().heapUsed / 1024 / 1024
      console.log(`Heap used ${used}`)
    }
  }
}

main()

@avkos avkos self-assigned this Jan 19, 2023
@avkos avkos closed this as completed Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.x 1.0 related issues 4.x 4.0 related Estimate Investigate
Projects
None yet
Development

No branches or pull requests

3 participants