@ -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
@ -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