diff --git a/index.js b/index.js index a2d5e29..d319373 100644 --- a/index.js +++ b/index.js @@ -199,6 +199,7 @@ class DHT extends EventEmitter { _request (to, command, target, value, onresponse, onerror) { const req = this.io.createRequest(to, null, command, target, value) + if (req === null) return null req.onresponse = onresponse req.onerror = onerror diff --git a/lib/query.js b/lib/query.js index f9f2a86..4d94b9a 100644 --- a/lib/query.js +++ b/lib/query.js @@ -311,6 +311,10 @@ module.exports = class Query extends Readable { this.inflight++ const req = this.dht._request(to, this.command, this.target, this.value, this._onvisitbound, this._onerrorbound) + if (req === null) { + this.destroy(new Error('Node was destroyed')) + return + } req.oncycle = this._oncyclebound } }