web3.js
web3.js copied to clipboard
unlockaccount spawns many nodejs defunct processes
I am getting a lot of [nodejs] [defunct] process when run this code. Is there a way to check if an account is already unlocked or lock the account to properly close the nodejs process it starts so that there are not too many nodejs defunct processes.
const Web3 = require('web3');
const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));
let txHashArray = [];
try {
if (web3.isConnected()) {
const abi = '[{"constant":false,"inputs":[{"name":"_int","type":"uint16"}],"name":"set","outputs":[{"name":"arrayLength","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"length","outputs":[{"name":"arrayLength","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"}]';
const contract = web3.eth.contract(JSON.parse(abi));
const contractAddress = '0x4D0f2e99a871A276da395538C8107275C17bCe12';
contractInstance = contract.at();
for (let i = 0; i < 1000; i++) {
web3.personal.unlockAccount(web3Config.defaultAccount,
web3Config.defaultAccountPwd);
/*
const txHash = contractInstance.set(i,{from:web3Config.defaultAccount, gas:'9040000', gasPrice:'0'});
txHashArray.push(txHash);
*/
console.log(i)
}
/*
// Write txHash to file to check later
var txfile = fs.createWriteStream('txfile.csv');
txfile.on('error', function(err) { /* error handling */ });
txHashArray.forEach(function(v) {
txfile.write(v + '\n');
});
txfile.end();
*/
} else {
console.log('web3 is not connected');
}
} catch (error) {
console.error(error);
}
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions