Skip to content

Commit

Permalink
don't try and abort a request that has already completed
Browse files Browse the repository at this point in the history
The fetch-mock library does not correctly handle the case of an abort
controller firing after a request has completed. This is a known issue
but not yet fixed upstream.

see wheresrhys/fetch-mock#847
  • Loading branch information
Alex Ashley authored and asrashley committed Jan 26, 2025
1 parent 94d39d4 commit 8f44b22
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions patches/fetch-mock+12.2.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
diff --git a/node_modules/fetch-mock/dist/esm/Router.js b/node_modules/fetch-mock/dist/esm/Router.js
index 599e79f..ef9ed5d 100644
--- a/node_modules/fetch-mock/dist/esm/Router.js
+++ b/node_modules/fetch-mock/dist/esm/Router.js
@@ -84,10 +84,19 @@ export default class Router {
const error = new DOMException('The operation was aborted.', 'AbortError');
const requestBody = request?.body || options?.body;
if (requestBody instanceof ReadableStream) {
- requestBody.cancel(error);
+ if (requestBody.locked) {
+ requestBody.getReader().cancel(error);
+ } else {
+ requestBody.cancel(error);
+ }
}
- if (callLog?.response?.body) {
- callLog.response.body.cancel(error);
+ const responseBody = callLog?.response?.body;
+ if (responseBody) {
+ if (responseBody instanceof ReadableStream && responseBody.locked) {
+ responseBody.getReader().cancel(error);
+ } else {
+ responseBody.cancel(error);
+ }
}
reject(error);
};

0 comments on commit 8f44b22

Please sign in to comment.