From 5c10db0e42534c743b2e909c319bd124af69565f Mon Sep 17 00:00:00 2001 From: DarkerInk Date: Wed, 18 Oct 2023 03:53:19 -0500 Subject: [PATCH 1/2] Update connection.js Changing how we connect to the net client so runtimes like bun will work (tested this on 1.0.6) --- lib/connection.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/connection.js b/lib/connection.js index 84382872..5d632f94 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -173,7 +173,10 @@ class Connection extends events.EventEmitter { if (!this.options.sslOptions) { this.netClient = new net.Socket({ highWaterMark: this.options.socketOptions.coalescingThreshold }); - this.netClient.connect(this.port, this.address, function connectCallback() { + this.netClient.connect({ + host: this.address, + port: parseInt(this.port, 10) + }, function connectCallback() { self.log('verbose', `Socket connected to ${self.endpointFriendlyName}`); self.bindSocketListeners(); self.startup(callback); @@ -187,7 +190,11 @@ class Connection extends events.EventEmitter { sslOptions.servername = this._serverName; } - this.netClient = tls.connect(this.port, this.address, sslOptions, function tlsConnectCallback() { + this.netClient = tls.connect({ + host: this.address, + port: parseInt(this.port, 10), + ...sslOptions + }, function tlsConnectCallback() { self.log('verbose', `Secure socket connected to ${self.endpointFriendlyName} with protocol ${self.netClient.getProtocol()}`); self.bindSocketListeners(); self.startup(callback); From eeb8eba85211ce02c0f7e88374dac5432dfb1c5b Mon Sep 17 00:00:00 2001 From: DarkerInk Date: Wed, 18 Oct 2023 03:55:25 -0500 Subject: [PATCH 2/2] Update streams.js In bun, for some reason when concating buffers if the length is set to undefined, bun returns a empty buffer. This fixes that (still works in node, tested on bun v1.06 and node v16.20.2+) --- lib/streams.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/streams.js b/lib/streams.js index 158cc8b7..8324eb17 100644 --- a/lib/streams.js +++ b/lib/streams.js @@ -289,7 +289,7 @@ Parser.prototype.addFrameBuffer = function (frameInfo, item) { */ Parser.prototype.getFrameBuffer = function (frameInfo, item) { frameInfo.buffers.push(item.chunk); - const result = Buffer.concat(frameInfo.buffers, frameInfo.bodyLength); + const result = Buffer.concat(frameInfo.buffers, frameInfo.bodyLength ?? frameInfo.buffers.reduce((acc, cur) => acc + cur.length, 0)); frameInfo.buffers = null; return result; };