diff --git a/lib/bcoin/miner.js b/lib/bcoin/miner.js index e62a9bce..d877147c 100644 --- a/lib/bcoin/miner.js +++ b/lib/bcoin/miner.js @@ -178,6 +178,8 @@ Miner.prototype.start = function start(version) { attempt.mineAsync(function(err, block) { if (err) { + if (!self.running) + return; self.emit('error', err); return self.start(); } @@ -363,6 +365,8 @@ function MinerBlock(options) { this.witness = options.witness; this.address = options.address; this.network = bcoin.network.get(options.network); + this.timeout = null; + this.callback = null; this.coinbase = new bcoin.tx(); this.coinbase.mutable = true; @@ -673,6 +677,10 @@ MinerBlock.prototype.mineAsync = function mine(callback) { if (!this.workerPool) return this.mine(callback); + callback = utils.once(callback); + + this.callback = callback; + function done(err, block) { self.workerPool.destroy(); callback(err, block); @@ -697,6 +705,10 @@ MinerBlock.prototype.destroy = function destroy() { clearTimeout(this.timeout); this.timeout = null; } + if (this.callback) { + this.callback(new Error('Destroyed.')); + this.callback = null; + } this.block = null; };