From 778f0ec9dd247a7483970acaabf2e71dfa99a16d Mon Sep 17 00:00:00 2001 From: Sadzurami Date: Thu, 22 Feb 2024 09:15:03 +0300 Subject: [PATCH] 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;