Browse Source

fix ontick bug if inflights is mutated during cb

v4
Mathias Buus 5 years ago
parent
commit
2a3e5b2721
  1. 10
      lib/io.js

10
lib/io.js

@ -25,6 +25,7 @@ class IO {
this._requests = new Array(65536)
this._pending = []
this._secrets = [ randomBytes(32), randomBytes(32) ]
this._ticking = false
this._tickInterval = setInterval(this._ontick.bind(this), 250)
this._rotateInterval = setInterval(this._onrotate.bind(this), 300000)
@ -156,7 +157,7 @@ class IO {
message,
buffer,
peer,
timeout: 4,
timeout: this._ticking ? 5 : 4, // if ticking this will be decremented after this fun call
tries: 0
}
@ -178,7 +179,9 @@ class IO {
}
_ontick () {
for (var i = this.inflight.length - 1; i >= 0; i--) {
this._ticking = true
for (var i = 0; i < this.inflight.length; i++) {
const req = this.inflight[i]
if (req.timeout === 2 && ++req.tries < TRIES) {
@ -191,7 +194,10 @@ class IO {
}
this._cancel(req.rid, ETIMEDOUT)
i-- // the cancel removes the entry so we need to dec i
}
this._ticking = false
}
send (buffer, peer) {

Loading…
Cancel
Save