From 962f972aea17e02b5f91f6b3fb1a020925a9fa2a Mon Sep 17 00:00:00 2001 From: David Huggins-Daines Date: Fri, 28 Feb 2025 11:25:52 -0500 Subject: [PATCH] Be sure to consume responses in case of error in downloading test files (issue 19580) As mentioned in https://nodejs.org/docs/latest-v20.x/api/http.html#httpgeturl-options-callback if a request results in an error, you still need to consume the data, or call `response.resume()`, or your code will hang waiting for the request to close. --- test/downloadutils.mjs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/downloadutils.mjs b/test/downloadutils.mjs index 6d80e2153..fd58e4f23 100644 --- a/test/downloadutils.mjs +++ b/test/downloadutils.mjs @@ -42,6 +42,7 @@ function downloadFile(file, url, redirects = 0) { .get(url, async function (response) { if ([301, 302, 307, 308].includes(response.statusCode)) { if (redirects > 10) { + response.resume(); reject(new Error("Too many redirects")); return; } @@ -50,12 +51,14 @@ function downloadFile(file, url, redirects = 0) { await downloadFile(file, redirectTo, ++redirects); resolve(); } catch (ex) { + response.resume(); reject(ex); } return; } if (response.statusCode !== 200) { + response.resume(); reject(new Error(`HTTP ${response.statusCode}`)); return; }