-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Timeout not throwing error with status TIMEOUT_ERROR #2915
Comments
Hmm, according to our tests at redux-toolkit/packages/toolkit/src/query/tests/fetchBaseQuery.test.tsx Lines 947 to 950 in 4c32e29
you should be getting {
status: 'TIMEOUT_ERROR',
error: 'AbortError: The user aborted a request.',
} Can you create a small reproduction? |
I will do a small reproduction as soon as I am free, but I think, the reason might be that |
I have the same problem. When I wrap fetchBaseQuery, I indeed get Edit: I'm using a web browser, so no react native |
That seems very weird. Could one of you provide a small reproduction for that? |
This should reproduce the problem: state/testApi.js import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
export const testApi = createApi({
reducerPath: 'test',
baseQuery: fetchBaseQuery({ baseUrl: 'http://google.nl', timeout: 1 }),
endpoints: (builder) => ({
getContent: builder.query({ query: () => 'test' }),
}),
});
// Add reducer/middleware to the state store React component: import testApi from 'state/testApi';
const App = (props) => {
const queryState = testApi.endpoints.getContent.useQuery();
console.log(queryState.error); // {name: 'AbortError', message: 'Aborted'}
} |
Just came across this bug myself using React Native. The transformErrorResponse on the endpoint shows the "TIMEOUT_ERROR" but the error that actually makes it to the useQuery hook is that "AbortError" / "Aborted" one. I also find it weird that I the case of a timeout aborting the action, even though the error is seen in the transformErrorResponse, any error returned there will not be used. The "AbortError" will ALWAYS be the error returned. |
I just tried it with the reproduction code above, but it works for me - please check out this CodeSandbox as a starter and see if you can give me a full working reproduction: https://codesandbox.io/s/hungry-ardinghelli-ysjxy2?file=/src/App.tsx |
I'm working on an Ionic React project, and after adding a timeout to This is the part of our code that, I think, should capture the error:
How should we catch the timeout error in user code? |
Honestly, with a full reproduction we maybe could just fix this. |
Look I really like this library, and I'm very thankful for its existence. That being said, hastily calling your users "lazy" is just, let us say, unprofessional. It's ok if you need a reproduction repo, I get it. But it's not ok to call names. |
Excuse me, my wording might have been slightly off, but it comes down to the same base message: So let me rephrase it and ask the same question I already asked twice above in this thread: Could you please create any kind of reproduction that actually shows this issue? From the source code of redux-toolkit/packages/toolkit/src/query/fetchBaseQuery.ts Lines 267 to 287 in 4c32e29
The only way I could even remotely assume this bug could appear would be if you use some kind of polyfil that throws if the AbortSignal is aborted after the fetch finishes, or tries to "re-run" the fetch mutliple times for whatever reason. (And even that only in a near-impossible race condition, because we do clear the timeout.) |
Thank you for your reply. I understand the frustration you are mentioning, and I didn't mean to be too harsh in my response. So let's clear the air here :) Also, I'll try to create a minimal repo that reproduces the issue. Hopefully for next week. Nevertheless, In the code you quoted, what happens if the timeout is really small, like 1 millisecond, will it raise the exception before entering the try-catch? Because in my case the error "disappears" when I increase the timeout value... |
Thanks, it would be greatly appreciated!
It would abort the AbortSignal, which would not do anything. The exception is thrown by Try it out: const controller = new AbortController()
controller.abort() has no effect apart from setting |
It took some time, but here I go. I made a small reproduction repo https://github.com/ifigueroap/redux-toolkit-timeout-bug Please let me know whether you can reproduce the issue, or if you need any further assistance. Best regards, |
It seems that there is a race condition. When a fetch request timeout calls So here abort() is called: redux-toolkit/packages/toolkit/src/query/fetchBaseQuery.ts Lines 276 to 279 in f63b862
And here is the race condition: redux-toolkit/packages/toolkit/src/createAsyncThunk.ts Lines 634 to 644 in f63b862
When |
Any update on this? Still getting |
Hey, PR #2401 shows that
fetchBaseQuery
should throw aTIMEOUT_ERROR
when time out delay is reached. However, I got an error without status{"message": "Aborted", "name": "AbortError"}
. I'm using"@reduxjs/toolkit": "^1.9.0"
with"react-native": "0.70.3"
,"react": "18.1.0"
. Here is my base API:The text was updated successfully, but these errors were encountered: