Repository navigation
fix: drain redirect response and resolve relative URLs in downloadFile #25375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -543,7 +543,9 @@ export async function downloadFile( | |
| new Error('Redirect response missing Location header'), | ||
| ); | ||
| } | ||
| downloadFile(res.headers.location, dest, options, redirectCount + 1) | ||
| res.resume(); // Drain response body to free the socket | ||
| const redirectUrl = new URL(res.headers.location, url).toString(); | ||
| downloadFile(redirectUrl, dest, options, redirectCount + 1) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Following redirects blindly while re-adding the |
||
| .then(resolve) | ||
| .catch(reject); | ||
| return; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While adding
res.resume()here is correct, the same logic is missing in the error paths within this redirect block. Specifically, if the redirect count is exceeded (line 538) or if theLocationheader is missing (line 542), the response body is not drained, leading to a socket leak. To ensure robust resource management, the response should be resumed in all cases where the body is not consumed.