pool: fix destroyed race condition.
This commit is contained in:
parent
1f22013ce0
commit
9c48cc9333
@ -126,7 +126,7 @@ function Peer(pool, addr, socket) {
|
||||
this.banScore = 0;
|
||||
|
||||
this.pingTimeout = null;
|
||||
this.pingInterval = 120000;
|
||||
this.pingInterval = 30000;
|
||||
|
||||
this.requestTimeout = 10000;
|
||||
this.requestMap = {};
|
||||
@ -658,6 +658,9 @@ Peer.prototype.sendVersion = function sendVersion() {
|
||||
*/
|
||||
|
||||
Peer.prototype.sendPing = function sendPing() {
|
||||
if (this.maybeStall())
|
||||
return Promise.resolve();
|
||||
|
||||
if (!this.version)
|
||||
return Promise.resolve();
|
||||
|
||||
@ -1018,6 +1021,9 @@ Peer.prototype.getData = function getData(items) {
|
||||
Peer.prototype._onPacket = co(function* onPacket(packet) {
|
||||
var unlock;
|
||||
|
||||
if (this.destroyed)
|
||||
throw new Error('Destroyed peer sent a packet.');
|
||||
|
||||
switch (packet.type) {
|
||||
case packetTypes.VERSION:
|
||||
case packetTypes.CMPCTBLOCK:
|
||||
|
||||
@ -1562,6 +1562,9 @@ Pool.prototype.getData = co(function* getData(peer, type, hash) {
|
||||
if (exists)
|
||||
return true;
|
||||
|
||||
if (peer.destroyed)
|
||||
throw new Errror('Peer is already destroyed (getdata).');
|
||||
|
||||
item = new LoadRequest(this, peer, type, hash);
|
||||
|
||||
if (type === this.txType) {
|
||||
@ -2359,7 +2362,7 @@ LoadRequest.prototype.start = function start() {
|
||||
*/
|
||||
|
||||
LoadRequest.prototype.finish = function finish() {
|
||||
if (this.pool.requestMap[this.hash]) {
|
||||
if (this.pool.requestMap[this.hash] === this) {
|
||||
delete this.pool.requestMap[this.hash];
|
||||
if (this.active) {
|
||||
this.active = false;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user