Skip to content

Commit 9a6149f

Browse files
jrainvilleiurimatias
authored andcommitted
fix(gethClient): clear timeout when call backing
1 parent b20bce9 commit 9a6149f

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/lib/modules/blockchain_process/gethClient.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,22 @@ class GethClient {
225225

226226
initDevChain(datadir, callback) {
227227
exec(this.listAccountsCommand(), {}, (err, stdout, _stderr) => {
228+
const readyTimeout = setTimeout(() => {
229+
this.child.kill();
230+
return cb(__('Geth dev command never returned a developer account'));
231+
}, 10 * 1000);
232+
233+
function cb(err) {
234+
clearTimeout(readyTimeout);
235+
callback(err);
236+
}
237+
228238
if (err || stdout === undefined || stdout.indexOf("Fatal") >= 0) {
229-
return callback(err || stdout);
239+
return cb(err || stdout);
230240
}
231241
this.config.unlockAddressList = this.parseListAccountsCommandResultToAddressList(stdout);
232242
if (this.config.unlockAddressList.length) {
233-
return callback();
243+
return cb();
234244
}
235245

236246
// No accounts. We need to run the geth --dev command for it to create the dev account
@@ -243,14 +253,9 @@ class GethClient {
243253
data = data.toString();
244254
if (data.indexOf('Using developer account') > -1) {
245255
this.child.kill();
246-
callback();
256+
cb();
247257
}
248258
});
249-
250-
setTimeout(() => {
251-
this.child.kill();
252-
return callback(__('Geth dev command never returned a developer account'));
253-
}, 10 * 1000);
254259
});
255260
}
256261

@@ -341,8 +346,11 @@ class GethClient {
341346
accountAddress = address;
342347
}
343348
if (accountAddress) {
344-
if(!(self.config && self.config.account && self.config.account.password)){
345-
console.warn(__("\n===== Password needed =====\nPassword for account {{account}} not found. Unlocking this account may fail. Please ensure a password is specified in config/blockchain.js > {{env}} > account > password.\n", {account: address, env: self.env}));
349+
if (!(self.config && self.config.account && self.config.account.password)) {
350+
console.warn(__("\n===== Password needed =====\nPassword for account {{account}} not found. Unlocking this account may fail. Please ensure a password is specified in config/blockchain.js > {{env}} > account > password.\n", {
351+
account: address,
352+
env: self.env
353+
}));
346354
}
347355
args.push("--unlock=" + accountAddress);
348356
return callback(null, "--unlock=" + accountAddress);

0 commit comments

Comments
 (0)