-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Cannot cancel a stream that already has a reader #3971
Comments
I have similar issue, but not the same. "TypeError: This stream has already been locked for exclusive reading by another reader" Im trying to request text from Form Data and Files too. But Form has 2 different methods, but not possible to read the request with both of them. Sorry if my code isnt efficent enough but im trying.
|
@MisteryPoints Try cloning the request object, and read data separately from that cloned object. Even I faced the same issue, and have solved it by following this approach -
|
@itsanirbanroy Thanks bro!, i did the same before in Aug 12, when i readed a bit of request documentation. |
It's working great from the loader of the routes with RemixJS 1.7.0, but I'm getting this error with a POST HTTP request from a simple action: export const action: ActionFunction = async ({ request }) => {
const formData = await request.formData();
const email = formData.get('email')?.toString();
try {
await httpRequest(`${apiURL}/auth`, {
method: 'POST',
body: JSON.stringify({
email,
}),
parseJSON: false,
timeout: 1000,
});
return redirect('/login');
} catch (error) {
return {
error: (error as Error)?.message,
};
}
}; Output: /node_modules/web-streams-polyfill/src/lib/readable-stream.ts:149
return promiseRejectedWith(new TypeError('Cannot cancel a stream that already has a reader'));
^
TypeError: Cannot cancel a stream that already has a reader
at ReadableStream.cancel (/node_modules/web-streams-polyfill/src/lib/readable-stream.ts:149:34)
at abort (/node_modules/@remix-run/web-fetch/src/fetch.js:75:18)
at AbortSignal.abortAndFinalize (/node_modules/@remix-run/web-fetch/src/fetch.js:91:4)
at AbortSignal.[nodejs.internal.kHybridDispatch] (node:internal/event_target:694:20)
at AbortSignal.dispatchEvent (node:internal/event_target:636:26)
at abortSignal (node:internal/abort_controller:292:10)
at AbortController.abort (node:internal/abort_controller:323:5)
at Timeout._onTimeout (/apps/webapp/app/utils/http.ts:21:42)
at listOnTimeout (node:internal/timers:559:17)
at processTimers (node:internal/timers:502:7) Please let me know and thanks for your help! |
I see this error when canceling a fetch request with For now, I decided not to use Remix's custom fetch library for that purpose. |
I also ran into this as well. For now, as a workaround (to @aniravi24's point of avoiding the web-fetch usage), I did the following:
"node-fetch": "^2",
|
This still seems to be an active issue, I just ran into it too. |
Also facing this issue, the following is my investigation I think this issue can't be solve by clone the request,
the test case below try to defer the controller abort, diff --git a/packages/fetch/src/fetch.js b/packages/fetch/src/fetch.js
index fcbc379..6a46f77 100644
--- a/packages/fetch/src/fetch.js
+++ b/packages/fetch/src/fetch.js
@@ -72,6 +72,8 @@ async function fetch(url, options_ = {}) {
const error = new AbortError('The operation was aborted.');
reject(error);
if (request.body) {
+ console.log('request.body', request.body)
+ console.log('request.body.locked', request.body.locked)
request.body.cancel(error);
}
diff --git a/packages/fetch/test/main.js b/packages/fetch/test/main.js
index cc02728..0b7d95f 100644
--- a/packages/fetch/test/main.js
+++ b/packages/fetch/test/main.js
@@ -1126,7 +1126,9 @@ describe('node-fetch', () => {
.and.have.property('name', 'AbortError')
]);
- controller.abort();
+ setTimeout(() => {
+ controller.abort();
+ }, 10)
return result;
}); I didn't solve this issue, need other people input. |
Also, attach a repository for reproduce this issue https://github.com/kayac-chang/remix-abort-test/tree/main https://gitpod.io/start/#kayacchang-remixabortte-0ohsnxppt54 |
I'm pretty sure Remix accepts PRs with a failing test case as a bug report, so if you're able to reproduce it in a test case and open a PR, that might bring this issue some attention. |
Thank you for the suggestion, I will do that as soon as possible. |
i found this issue at fetch writeToStream(request_, request); |
when the fetch request times out, abort will be triggered and an error will be throw |
@kayac-chang is spot on.
This is a bit of a dealbreaker, as a server timeout (or a 500 error) is currently not |
I see this was assigned and then unassigned - any progress on this? |
I see the Issue comes from people using Remix. In my case, it was breaking because I was reading the body more than once. Here you can read more about it. |
The Remix team has been working on that; they want to remove the polyfill on node> = 18. Thank the team for the fantastic work here! 🙏🙏🙏 |
+1. Calling an endpoint that returns in 2s with a 1s timeout triggers the un-catchable error and crushes the process: try {
const resp = await fetch("https://run.mocky.io/v3/b2cca8a5-81b6-4293-b957-774c399c416b?mocky-delay=2000ms",
{
method: "POST",
signal: AbortSignal.timeout(1000),
});
} catch (error: any) {
console.error(error)
} output:
|
We also started encountering this error, something we see is that it only happens for Here is our workaround
|
Please opt into "nativeFetch" on your |
We're running into this error as well, how does one opt into "nativeFetch" on the installGlobals() call? It does not accept any parameters. 🤔 Edit: I see we need to update to the latest version of remix then you can do:
|
What version of Remix are you using?
1.6.7
Steps to Reproduce
I'm executing a http request from a route Action but I'm getting this error because Server is busy (not responding):
I created a simple utility to support timeout with fetch:
Then I'm using that method to execute a POST request:
Also I'm already using CatchBoundary and ErrorBoundary for this page:
Expected Behavior
Be able to get the error message using
useActionData
Hook from Remix, it's working for other validations before executing the HTTP request.Actual Behavior
Getting an unexpected exception:
Thanks for your help! <3
The text was updated successfully, but these errors were encountered: