From b3e4673882a0dee7ede64a149585d15737e0162c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20R=C3=B6gner?= Date: Sun, 10 May 2020 19:36:54 +0200 Subject: [PATCH 1/2] Added error handling when writing to socket. --- dist/lib/connection.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/dist/lib/connection.js b/dist/lib/connection.js index d798118..823dc7b 100644 --- a/dist/lib/connection.js +++ b/dist/lib/connection.js @@ -149,13 +149,23 @@ class Connection extends typed_events_1.default { that.emit('debug', "DEBUG: >>>> Send Protobuf=" + JSON.stringify(message.toJSON(), null, 2)); let messageLength = Buffer.from(varint.encode(encrypted.length)); let bytes = Buffer.concat([messageLength, encrypted]); - that.socket.write(bytes); + try { + that.socket.write(bytes); + } catch (e) { + that.emit('debug', "DEBUG: >>>> Error while writing to socket"); + reject(); + } } else { that.emit('debug', "DEBUG: >>>> Send Protobuf=" + JSON.stringify(message.toJSON(), null, 2)); let messageLength = Buffer.from(varint.encode(data.length)); let bytes = Buffer.concat([messageLength, data]); - that.socket.write(bytes); + try { + that.socket.write(bytes); + } catch (e) { + that.emit('debug', "DEBUG: >>>> Error while writing to socket"); + reject(); + } } if (!waitForResponse) { resolve(new message_1.Message(message)); From a1882e8aecc420f275207ee0133c7b1df22e13bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20R=C3=B6gner?= Date: Sun, 10 May 2020 19:38:08 +0200 Subject: [PATCH 2/2] Fixed a bug in the error handling. --- dist/lib/connection.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dist/lib/connection.js b/dist/lib/connection.js index 823dc7b..805916e 100644 --- a/dist/lib/connection.js +++ b/dist/lib/connection.js @@ -154,6 +154,7 @@ class Connection extends typed_events_1.default { } catch (e) { that.emit('debug', "DEBUG: >>>> Error while writing to socket"); reject(); + return; } } else { @@ -165,6 +166,7 @@ class Connection extends typed_events_1.default { } catch (e) { that.emit('debug', "DEBUG: >>>> Error while writing to socket"); reject(); + return; } } if (!waitForResponse) {