web3.js icon indicating copy to clipboard operation
web3.js copied to clipboard

unlockaccount spawns many nodejs defunct processes

Open aas312 opened this issue 8 years ago • 1 comments

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);
}

aas312 avatar Dec 06 '17 14:12 aas312

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

github-actions[bot] avatar Jul 04 '20 00:07 github-actions[bot]