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
This commit is contained in:
CosminPerRam 2025-06-02 00:30:22 +03:00 committed by GitHub
parent 49093f0b0f
commit da78c84c03
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 2 deletions

View file

@ -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)

View file

@ -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)