-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
MaxListenersExceededWarning in 4.X #6554
Comments
seems issue in setting Warning Threshold. We will investigate and fix. |
Hello @M0cK1nG-b1Rd, |
hey, I am currently using nodejs of version
I think it's rather difficult to refer to a cloud ide because I am currently using web3js to interact with bsc mainnet via a self-build bsc node on my server. It's rather hard to reproduce the whole environment. Is there any alternatives? |
Thanks @M0cK1nG-b1Rd, |
heyyy, seems I made a mistake. I use
and my const checkSingleToken = async (newTokenInfo, tokenAddress) => {
if (newTokenInfo.safe == 6) {
try {
const owner = await new Contract(standardTokenAbi, tokenAddress, web3).methods.owner().call();
newTokenInfo.owner = owner.toLowerCase();
} catch (error) {
}
}
worker.postMessage({ "action": "checkSingleTokenIsSafe", "data": newTokenInfo });
}; the trace indicates that the warning comes from BTW, This code is originally used in web3.js of version const owner = await new web3.eth.Contract(standardTokenAbi, tokenAddress).methods.owner().call(); to const owner = await new Contract(standardTokenAbi, tokenAddress, web3).methods.owner().call(); For this, I recheck my code and I am sure I am not using
|
Thanks @M0cK1nG-b1Rd, |
heyy, I create a minimun test case to stablely reproduce the problem in https://github.com/M0cK1nG-b1Rd/web3js_reproduce, might need a bsc node to run the script |
Thanks @M0cK1nG-b1Rd |
I run the node natively and I am not so familiar with bsc inside docker. Building a node yourself occupies so many server resources so I actually recommend using some third party node provider, as long as it supports wss. I tried quicknode and it can also reproduce this issue. Setup a bsc node in quicknode dashboard and choose free plan will be just ok. |
Hi @M0cK1nG-b1Rd , However, if you updated to the latest (4.5.0) and you are still facing this issue. Feel free to reopen it. And if you faced a different issue, you can open a new issue for that. And a note on the side, you do not need to instantiate new Contract instance everytime you are calling a contract method. const checkSingleToken = async (newTokenInfo, tokenAddress) => {
if (newTokenInfo.safe == 6) {
try {
const owner = await new Contract(standardTokenAbi, tokenAddress, web3).methods.owner().call();
newTokenInfo.owner = owner.toLowerCase();
} catch (error) {
}
}
worker.postMessage({ "action": "checkSingleTokenIsSafe", "data": newTokenInfo });
}; You can have: const myContract = new Contract(standardTokenAbi, tokenAddress, web3);
const checkSingleToken = async (newTokenInfo, tokenAddress) => {
if (newTokenInfo.safe == 6) {
try {
const owner = await myContract.methods.owner().call();
newTokenInfo.owner = owner.toLowerCase();
} catch (error) {
}
}
worker.postMessage({ "action": "checkSingleTokenIsSafe", "data": newTokenInfo });
}; |
My code is written like this, using web3js version 4.5.0, and I still receive this warning: (node:1) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [ClientHttp2Session]. Use emitter.setMaxListeners() to increase the limit (Use node --trace-warnings ... to show where the warning was created). this.web3 = new Web3(new Web3.providers.WebsocketProvider(providerUrl));
this.contracts = contractConfig.map((config) => {
return new this.web3.eth.Contract(config[1].abi, config[0]);
});
this.contracts.forEach((contract) => {
console.log(`[${new Date().toLocaleString()}] EventListener listening contractAddress ${contract.options.address} start...`);
contract.events.allEvents(
{fromBlock: process.env.FROM_BLOCK}
)
.on('data', (event) => {
// ...
})
}); |
hello, I am using web3.js of
4.2.0
to listen both pending and confirmed transactions. I get the warning of(node:3862464) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 message listeners added to [EventEmitter]. Use emitter.setMaxListeners() to increase limit
when my code runs for a while. My code looks likeand here is my code when initializing web3 project, I try to use setMaxListenerWarningThreshold as mentioned in #1494, but in vain. Can someone help?
The text was updated successfully, but these errors were encountered: