From 5b08d21966e90fc869dab93a742e9843d512388c Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Fri, 24 Feb 2023 21:43:58 -0700 Subject: [PATCH] Prevent double callback --- .../activitypub_actor_search_main.ans | Bin 2839 -> 2848 bytes core/http_util.js | 18 +++++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/art/themes/luciano_blocktronics/activitypub_actor_search_main.ans b/art/themes/luciano_blocktronics/activitypub_actor_search_main.ans index 1f7a6074d7f19ed397b482f455114215d406c6e1..81ad15621f3741f3e2eec6f52a4e54120b7d60e4 100644 GIT binary patch delta 47 zcmbO(wm@vd8&)YpYh#04ed%ZeYh$C_q{QTG>1eQ!g2Lv%te;qzjZC&p{=}sU0Ai;P AJ^%m! delta 32 ocmZ1=HeGDP8&+mx^W4eNtn!oZafWWrVe4UGHZ)y3`8Ss;0KF3nNB{r; diff --git a/core/http_util.js b/core/http_util.js index 98f8936b..a1469c2d 100644 --- a/core/http_util.js +++ b/core/http_util.js @@ -70,6 +70,14 @@ function _makeRequest(url, options, cb) { } } + let cbCalled = false; + const cbWrapper = (e, b, r) => { + if (!cbCalled) { + cbCalled = true; + return cb(e, b, r); + } + }; + const req = https.request(url, options, res => { let body = []; res.on('data', d => { @@ -80,7 +88,7 @@ function _makeRequest(url, options, cb) { body = Buffer.concat(body).toString(); if (res.statusCode < 200 || res.statusCode > 299) { - return cb( + return cbWrapper( Errors.HttpError( `URL ${url} HTTP error ${res.statusCode}: ${truncate(body, { length: 128, @@ -89,7 +97,7 @@ function _makeRequest(url, options, cb) { ); } - return cb(null, body, res); + return cbWrapper(null, body, res); }); }); @@ -98,17 +106,17 @@ function _makeRequest(url, options, cb) { httpSignature.sign(req, options.sign); } catch (e) { req.destroy(); - return cb(Errors.Invalid(`Invalid signing material: ${e}`)); + return cbWrapper(Errors.Invalid(`Invalid signing material: ${e}`)); } } req.on('error', err => { - return cb(err); + return cbWrapper(err); }); req.on('timeout', () => { req.destroy(); - return cb(Errors.Timeout('Timeout making HTTP request')); + return cbWrapper(Errors.Timeout('Timeout making HTTP request')); }); if (options.body) {