From 778f0ec9dd247a7483970acaabf2e71dfa99a16d Mon Sep 17 00:00:00 2001 From: Sadzurami Date: Thu, 22 Feb 2024 09:15:03 +0300 Subject: [PATCH 1/2] fix uncaught exceptions --- components/connection_protocols/tcp.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/components/connection_protocols/tcp.js b/components/connection_protocols/tcp.js index e30ff4a6..448573a5 100644 --- a/components/connection_protocols/tcp.js +++ b/components/connection_protocols/tcp.js @@ -162,7 +162,12 @@ class TCPConnection extends BaseConnection { buf.writeUInt32LE(data.length, 0); buf.write(MAGIC, 4); data.copy(buf, 8); - this.stream.write(buf); + + try { + this.stream.write(buf); + } catch (error) { + this._debug('Error writing to socket: ' + error.message); + } } /** @@ -187,7 +192,14 @@ class TCPConnection extends BaseConnection { } } - let message = this.stream.read(this._messageLength); + let message; + + try { + message = this.stream.read(this._messageLength); + } catch (error) { + this._debug('Error reading from socket: ' + error.message); + } + if (!message) { this._debug('Got incomplete message; expecting ' + this._messageLength + ' more bytes'); return; From 2e64a1a5a0f3ed344855f0fbcc7ccea3ff2fe9ba Mon Sep 17 00:00:00 2001 From: Sadzurami Date: Thu, 22 Feb 2024 09:29:28 +0300 Subject: [PATCH 2/2] tweaks --- components/connection_protocols/tcp.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/components/connection_protocols/tcp.js b/components/connection_protocols/tcp.js index 448573a5..6006e154 100644 --- a/components/connection_protocols/tcp.js +++ b/components/connection_protocols/tcp.js @@ -158,6 +158,11 @@ class TCPConnection extends BaseConnection { data = SteamCrypto.symmetricEncryptWithHmacIv(data, this.sessionKey); } + if (!this.stream) { + this._debug('Tried to send message, but there is no stream'); + return; + } + let buf = Buffer.alloc(4 + 4 + data.length); buf.writeUInt32LE(data.length, 0); buf.write(MAGIC, 4); @@ -192,8 +197,12 @@ class TCPConnection extends BaseConnection { } } - let message; + if (!this.stream) { + this._debug('Tried to read message, but there is no stream'); + return; + } + let message; try { message = this.stream.read(this._messageLength); } catch (error) {