workers. fix inv relaying.

This commit is contained in:
Christopher Jeffrey 2016-05-22 18:13:54 -07:00
parent c71e7646d3
commit e8f5be9830
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 34 additions and 3 deletions

View File

@ -218,6 +218,9 @@ Miner.prototype.stop = function stop() {
this.attempt.destroy();
this.attempt = null;
}
if (this.workerPool)
this.workerPool.destroy();
};
/**

View File

@ -1098,8 +1098,8 @@ Peer.prototype._handleGetData = function handleGetData(items) {
return;
utils.forEachSerial(check, function(item, next) {
var witness = item.type & constants.WITNESS_MASK;
var type = (item.type & ~constants.WITNESS_MASK) !== 0;
var type = item.type & ~constants.WITNESS_MASK;
var witness = (item.type & constants.WITNESS_MASK) !== 0;
var hash = item.hash;
var i, tx, data;

View File

@ -50,6 +50,24 @@ utils.inherits(Workers, EventEmitter);
Workers.CORES = getCores();
/**
* Global list of workers.
* @type {Array}
*/
Workers.children = [];
/**
* Cleanup all workers on exit.
*/
Workers.cleanup = function cleanup() {
while (Workers.children.length > 0)
Workers.children.pop().destroy();
};
Workers._exitBound = false;
/**
* Spawn a new worker.
* @param {Number} id - Worker ID.
@ -58,7 +76,7 @@ Workers.CORES = getCores();
Workers.prototype.spawn = function spawn(id) {
var self = this;
var child;
var i, child;
bcoin.debug('Spawning worker process: %d', id);
@ -72,6 +90,9 @@ Workers.prototype.spawn = function spawn(id) {
bcoin.debug('Worker %d exited: %s', child.id, code);
if (self.children[child.id] === child)
self.children[child.id] = null;
i = Workers.children.indexOf(child);
if (i !== -1)
Workers.children.splice(i, 1);
});
child.on('packet', function(job, body) {
@ -87,6 +108,13 @@ Workers.prototype.spawn = function spawn(id) {
self.emit('error', new Error('Unknown packet: ' + body.name));
});
Workers.children.push(child);
if (!Workers._exitBound) {
process.once('exit', Workers.cleanup);
Workers._exitBound = true;
}
return child;
};