diff --git a/lib/bcoin/peer.js b/lib/bcoin/peer.js index 5730386d..85ef0241 100644 --- a/lib/bcoin/peer.js +++ b/lib/bcoin/peer.js @@ -244,13 +244,24 @@ Peer.prototype.destroy = function destroy() { // Private APIs Peer.prototype._write = function write(chunk) { + var self = this; + if (this.destroyed) return; if (!this.socket) { - return this.once('socket', function() { - this._write(chunk); - }); + if (!this._bchunks) { + this._bchunks = []; + this.once('socket', function() { + var chunks = self._bchunks; + delete self._bchunks; + chunks.forEach(function(chunk) { + self._write(chunk); + }); + }); + } + this._bchunks.push(chunk); + return; } if (NodeBuffer)