Skip to content
Myr

Fix memory leak, clean up body streams after retry (#651)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fixes #650

authored by Haidong Pang · committed by GitHub · parent 5dc572d · Browse files · 3 files+9 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Seth Holladay <me@seth-holladay.com>

Diff stats

3 files+9 added−1 removed

  • other:+9 added−1 removed

3 files+9 added−1 removed

modified:.github/workflows/main.yml+1 added-1 removed
modified:source/core/Ky.ts+7 added
34 unmodified lines
35 }3637 // Delay the fetch so that body method shortcuts can set the Accept header38 await Promise.resolve();39 // Before using ky.request, _fetch clones it and saves the clone for future retries to use.40 // If retry is not needed, close the cloned request's ReadableStream for memory safety.41 let response = await ky._fetch();4243 for (const hook of ky._options.hooks.afterResponse) {44 // eslint-disable-next-line no-await-in-loop
20 unmodified lines
6566 throw error;67 }6869 // Now that we know a retry is not needed, close the ReadableStream of the cloned request.70 if (!ky.request.bodyUsed) {71 await ky.request.body?.cancel();72 }7374 // If `onDownloadProgress` is passed, it uses the stream API internally75 if (ky._options.onDownloadProgress) {76 if (typeof ky._options.onDownloadProgress !== 'function') {77 throw new TypeError('The `onDownloadProgress` option must be a function');
259 unmodified lines
modified:package.json+1 added