-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Infinite loop when using a cache-and-network fetchPolicy #7436
Comments
@Alin13 It looks like these data are paginated using a Relay-style connection/edges API. Since you didn't mention anything about your A few side notes:
|
Well, I don't really need the pagination here, so I assume that if I remove the Relay structure it will work as expected. I never used any type or field policies and it's a little hard to understand exactly what needs to be done there, but as I understand, the cache keys are generated using the name of the field plus the serialized arguments. In my case I have different year and dates variables, so I expected that there will be no conflict between them. I'll try to remove the relay structure and I'll read the docs again. Thank you! Edit: @benjamn I changed the query so that I only have previousYearData subquery and I also removed some variables / filters:
and these are the variables of the query:
and I still have an infinite loop. So, I think is not related to the relay structure, but I'll try to remove it also. Can it be related to the size of the response (because it's pretty big)? Edit2: yes, I think this is related to the actual size of the response. If I limit the results to 100 entries everything works normally. Any ideas how to fix this? |
That is an interesting find! The places We see infinite loops are with big responses as well, i.e. metric data. For such types/resolvers we've set |
I managed to fix this by reducing the size of the response (we had over 30000 results initially, but we made some aggregations on the backend side and currently have ~500 results). But, I think this is still an issue with big responses. From my point of view, it doesn't make sense to have keyArgs or other configurations if by default all the arguments + the name of the field are used to cache the values. For example, I have those two queries:
and this
The first query uses cache-and-network fetchPolicy, the second uses the default (cache-first). We can clearly see that dateType filter is different in each query. These two queries are triggered in the same time: I get the result from the first one, I get the result from the second one and after this the first one gets retriggered. Why? How to avoid this extra call? |
@Alin13 Do you have any field policies (like |
@benjamn No extra configuration, only the default. |
Hi, I am encountering the same issue with an infinite loop when a query response contains a lot of data. Let me know if you need more details. |
So the exact value for which this infinite loop starts happening is |
Related: #6888 |
One note for people currently struggling with this issue. It is likely fixed in 3.4 thanks to certain optimizations with regard to canonicalization of InMemoryCache result objects (#7439). I will have a larger post-mortem on this issue by end of day today, but in the meantime, please try the 3.4 beta and see if that helps. |
Right so the TL;DR is that this issue is “fixed” in 3.4 and you should jump on the beta/rc when you get the chance. So what’s happening: Why is this happening for large-ish values?The Why is this happening for nested queries only?The nested query stuff is a red herring. The reality is that the Why does
|
I tried with 3.4.0-rc.2 and still see this issue. Is it confirmed that it should be fixed there @brainkim? |
@chillyistkult Just checked against 3.4.0-rc.3 and it seems to still be fixed. If you have a reproduction for the behavior you’re seeing I am always happy to take a look! |
@martinjlowm are there any additional details you can provide to help us determine if this is an Apollo Client issue? What does invocations mean in this context? Were you able to investigate further to determine if AC is the cause here? |
Hi @hwillson , I did have a closer look - I believe this was an effect of a thrown invariant error for some, but not something that applied for all clients. At least, it was easy for me to replicate if an API response didn't include any data (4XX errors). I saw:
and immediately after, an unrelated query started to go crazy. Oh, and the invocations are API requests over a period of 5 minutes per data point. I'll try to see if I can gather more information and perhaps even isolate it to a particular RC bump. |
I think perhaps it's this line: GitHub eats the pound in the link :< Right off the bat, I cannot say why the client would attempt to keep refetching a triggered query from this though. |
This is super helpful @martinjlowm - thanks for this! |
I managed to replicate some infinite loop on rc.6. I tried setting a couple of breakpoints just to see how the logic behaved. The variables to the query of interest does not change (same reference). Hope it's helpful - this is without any invariant errors. You can see the red bars switching between two states as if there were two queries that raced one another. https://www.icloud.com/iclouddrive/0H_M5_zserYxCERARXXiiIMRg#Screen_Recording_2021-06-14_at_22.56 I can confirm downgrading to rc.0 resolved it for us. ~1800 I deployed rc.6 again and a couple hours later, around midnight, I reverted just @apollo/client to rc.0 and that is where the drop of requests is. This one is CloudFront metrics of all resource requests in general. |
Fixes #8331 and #6915, and should help with the underlying cause of #7436 (comment)
Fixes #8331 and #6915, and should help with the underlying cause of #7436 (comment)
We get infinite looping as well and the global overrides are still broken |
this makes me lose confidence : https://tomoima525.medium.com/pitfalls-i-fell-into-during-apollo-client-3-0-migration-4829bfe0a45a |
I can confirm this still happens 3.3.7 we had network-only and still it triggered. |
Any solution to this problem guys ?? |
Try disabling babel-plugin-graphql-tag |
Intended outcome:
I have a component that retrieves some data using useQuery and renders a chart. Until now I used these options:
But now I realized that I have some data that may change and I need it to be up-to-date. I still want to use the cache, so I think that cache-and-network fetchPolicy would be the best in this case.
Actual outcome:
When I change the fetchPolicy to cache-and-network or network-only I end up having an infinite loop. This doesn't happen when I use no-cache.
This is how the component looks like:
Versions
@apollo/client 3.2.0
I assume this is a cache issue, but I'm not sure if it's my fault or not and I don't know how to fix it.
Any ideas?
Thank you for your time!
Edit: I also think that defaultOptions is not working correctly. I have these options set when I create the apollo client instance:
First time when I render a component that queries some data I see the network request. If I switch to another view and then come back, I see no request (it's retrieved from the cache - cache-first?). Anyway, if I use fetchPolicy: 'cache-and-network' option inside useQuery I always see the request at component mount. Is this the expected behavior ?
The text was updated successfully, but these errors were encountered: