Skip to content

Commit

Permalink
Clean up orphan ReadableStream remaining after retry (#650)
Browse files Browse the repository at this point in the history
  • Loading branch information
HaidongPang committed Nov 7, 2024
1 parent 3ba40cc commit 7ac4c92
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions source/core/Ky.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export class Ky {

// Delay the fetch so that body method shortcuts can set the Accept header
await Promise.resolve();
// Before using ky.request, _fetch clones a new Request for retries preparation.
// If retry is not needed, close the original Request ReadableStream for memory safety.
let response = await ky._fetch();

for (const hook of ky._options.hooks.afterResponse) {
Expand Down Expand Up @@ -63,6 +65,11 @@ export class Ky {
throw error;
}

// Now, it can be determined that a retry is not needed,
// close the ReadableStream of the ky.request.
if (!ky.request.bodyUsed){

Check failure on line 70 in source/core/Ky.ts

View workflow job for this annotation

GitHub Actions / Node.js 18

Missing space before opening brace.
await ky.request.arrayBuffer();
}
// If `onDownloadProgress` is passed, it uses the stream API internally
/* istanbul ignore next */
if (ky._options.onDownloadProgress) {

Check failure on line 75 in source/core/Ky.ts

View workflow job for this annotation

GitHub Actions / Node.js 18

Expected blank line before this statement.
Expand Down

0 comments on commit 7ac4c92

Please sign in to comment.