From a6421615fc86d8ae1c1493a1bc19a978612a05a9 Mon Sep 17 00:00:00 2001 From: Jamie Scott Date: Tue, 13 Feb 2024 17:58:17 +0000 Subject: [PATCH] Fix ~2min hang seen when making requests since changing to Node 20 The default for keepAlive on https request changed from false to true in Node 19 https://github.com/nodejs/node/issues/47228 --- main.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/main.js b/main.js index 73d8fa11..f96dce4a 100644 --- a/main.js +++ b/main.js @@ -130,8 +130,8 @@ function constructPayload(inputs, callback) { // Send a Slack notification function notifySlack(payload) { + console.log("Sending message to Slack..."); const url = new URL(process.env.SLACK_WEBHOOK_URL); - const options = { hostname: url.hostname, port: 443, @@ -141,8 +141,8 @@ function notifySlack(payload) { "Content-Type": "application/json", "Content-Length": payload.length, }, + agent: new https.Agent({ keepAlive: false }), }; - const req = https.request(options, res => { if (res.statusCode === 200) { console.log("Sent message to Slack OK"); @@ -150,7 +150,6 @@ function notifySlack(payload) { console.log("Failed to post to Slack!", res); } }); - req.write(payload); req.end(); }