From da78c84c0390d04751c441c23e80e2503d2469d0 Mon Sep 17 00:00:00 2001 From: CosminPerRam Date: Mon, 2 Jun 2025 00:30:22 +0300 Subject: [PATCH] fix(core): throwing in tcpSend onData callback would crash (#705) * fix(core): throwing in tcpSend onData callback would crash * docs: update changelog for these changes --- CHANGELOG.md | 1 + protocols/core.js | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4815e49..b635b1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * Feat: 7 Days to Die get more optional Telnet data via an option (#693) * Feat: Update OpenTTD (By @mwkaicz #695) * Fix: Skip non-response packets in protocol-battlefield (By @cetteup #704) +* Fix: throwing in tcpSend onData callback would crash gamedig (#705, thanks @cetteup) ## 5.3.0 * Docs: Arma Reforger query setup note (#670, thanks @xCausxn) diff --git a/protocols/core.js b/protocols/core.js index b53c2e8..9c20a0f 100644 --- a/protocols/core.js +++ b/protocols/core.js @@ -222,11 +222,16 @@ export default class Core extends EventEmitter { async tcpSend (socket, buffer, ondata) { let timeout try { - const promise = new Promise((resolve, _reject) => { + const promise = new Promise((resolve, reject) => { let received = Buffer.from([]) const onData = (data) => { received = Buffer.concat([received, data]) - const result = ondata(received) + let result + try { + result = ondata(received) + } catch (e) { + reject(e) + } if (result !== undefined) { socket.removeListener('data', onData) resolve(result)