From e4401864349349d34b51c9fd16de7b601f0ea0e1 Mon Sep 17 00:00:00 2001 From: Robin Summerhill Date: Fri, 18 Dec 2020 22:18:39 +0000 Subject: [PATCH] Fix destroying wrong this when server error received --- lib/Client.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/Client.js b/lib/Client.js index 93e062f..561d341 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -166,7 +166,7 @@ class Client extends Socket { } /* - * Send a message to the server. This method returns a Writable stream object + * Send a message to the server. This method returns a Writable stream object * for sending the frame body content. */ send(headers, options) { @@ -215,7 +215,7 @@ class Client extends Socket { headers = {destination: headers}; } - let id = headers.id !== undefined ? + let id = headers.id !== undefined ? headers.id : this._nextSubcriptionId++; while (this._subscriptions[id] !== undefined) { @@ -328,7 +328,7 @@ class Client extends Socket { } }).end(this._finishOutput.bind(this)); - // Keep the transport output open until the receipt is processed just in + // Keep the transport output open until the receipt is processed just in // case the transport is not configured to handle half-open connections. this._disconnecting = true; @@ -432,9 +432,11 @@ function onError(frame) { const content = new BufferWritable(Buffer.alloc(ERROR_MAX_CONTENT_LENGTH)); + const self = this; + frame.on('end', function() { error.longMessage = content.getWrittenSlice().toString(); - this.destroy(error); + self.destroy(error); }); frame.pipe(content);