From 6c6581cb743a9f4ebfd1c1cae04b367424b570c8 Mon Sep 17 00:00:00 2001 From: SAY-5 Date: Thu, 30 Apr 2026 11:20:52 -0700 Subject: [PATCH] fix(http): return after reject so promise doesn't double-settle (#11) Signed-off-by: SAY-5 --- src/http.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/http.js b/src/http.js index b2018d1..62119a4 100644 --- a/src/http.js +++ b/src/http.js @@ -19,7 +19,10 @@ module.exports.sendHttp = async function (_data, _host, _port, _path, _auth) { return new Promise((resolve, reject) => { var req = http.request(options, (res) => { if (res.statusCode < 200 || res.statusCode > 299) { - reject(new Error('Failed to process the request, status Code: ', res.statusCode)); + // Without `return`, the request continued to drain + // `data`/`end` and called `resolve(result)` later, settling + // the promise twice (#11). + return reject(new Error('Failed to process the request, status Code: ', res.statusCode)); } res.setEncoding('utf8'); var dataBuffer = ''; @@ -30,7 +33,10 @@ module.exports.sendHttp = async function (_data, _host, _port, _path, _auth) { res.on('end', () => { xml2jsparser(dataBuffer, (err, result) => { if (err) { - reject(new Error('Data Parsing error', err)); + // Same shape: the `resolve(result)` below ran + // immediately after `reject` and the promise + // settled twice (#11). + return reject(new Error('Data Parsing error', err)); } resolve(result); });