-
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
Queries hang and are not issued on network requests #9690
Comments
FWIW, we're also using const defaultOptions = {
watchQuery: {
fetchPolicy: 'no-cache',
errorPolicy: 'ignore',
},
query: {
fetchPolicy: 'no-cache',
errorPolicy: 'all',
},
};
|
@andreialecu Do you think you could put together a small runnable reproduction reproducing the regression? Or open a PR with a failing test (no need to fix it; we will investigate)? |
@benjamn the only change I see in 3.6.3 that could impact apollo-angular in any way is the one from this commit: 77119b0 The other changes seem to be react only. I'm not sure if I'll be able to reproduce it in isolation, since it's random when it starts happening. It could be a race condition of some sort with the batching link. I will try to investigate further. |
You can test your theory about that commit by running these commands locally: git clone git@github.com:apollographql/apollo-client.git
cd apollo-client
npm install
git revert 77119b06b165dbcb02d8ea7aeef17a12a08d059c
npm run build
cd dist
npm pack
cd .. That will give you a cd ~/path/to/your/app
npm i ~/path/to/apollo-client/dist/apollo-client-3.6.3.tgz Hope that helps with your investigation (or at least is easier than creating a reproduction)! |
@benjamn somehow I'm not able to reproduce this early today, so I'm very confused. Yesterday it was reproducible every single time in production, staging and development - but it was occurring during peak times. We use graphql subscriptions and there's a lot of chatter over them, that's the only thing that could be relevant. One of the subscriptions then triggers a query on a certain condition. I'll try to reproduce it during the next peak. The problems cleared up for all of our customers after deploying a downgrade to 3.4.17 initially as per my comment in #9456 (comment) I've then tried upgrading up until 3.6.2 and I couldn't reproduce it. On 3.6.3 it was reproducible again. Peak times were fading by that point, so it might be possible the problem isn't exactly between 3.6.2 and 3.6.3 but could be earlier. I'll continue monitoring this over the next few days. |
I have an update. It appears this also happens on 3.6.2 (deployed it in production earlier) so is not a recent regression in 3.6.3. It seems to be related to peak times somehow (a lot of subscriptions chatter at least). I have reverted to 3.4.17 for now where everything seems fine. I haven't yet checked 3.5.x. Since this happens in apollo angular I assume it's an issue in the core and not the react part. |
@benjamn another update. I've been troubleshooting this today and setting breakpoints once it started happening. Seems when it hangs it starts hitting this line of code: But the error is swallowed somewhere and is never thrown. I'm not sure if it's apollo-angular hiding it. This is with 3.6.2 I found #7608 which seems related. |
I tracked this down further and it seems to be caused by various rxjs observables interacting with each other and restarting some subscriptions as a side-effect. Seems to be similar to what has been reported in this comment: #7608 (comment) Notice the screenshot for a stack trace:
This ends up cascading through various observables and tearing down and restarting a |
Actually the plot thickens. I've changed some things so that those observables don't resubscribe. This prevented the "Observable cancelled prematurely" from happening, but the queries still hang. 🤔 |
So it appears that there's a callback being added to I think it's not being called most likely due to a race condition/or teardown situation similar to the one causing the "Observable cancelled prematurely" error. The problem seems to be related to Possibly relevant: apollo-client/src/core/QueryManager.ts Lines 991 to 996 in da3355c
apollo-client/src/core/QueryManager.ts Lines 1159 to 1165 in da3355c
I can reproduce it consistently, if it would help to set up a screen sharing session at some point feel free to DM me on Twitter. |
I tried various versions, I wasn't able to reproduce this on |
@benjamn if you have any suggestions which commits I could revert from |
Thanks for all the details @andreialecu! I think you're on the right track, and the I can do some digging/testing today with this information. I'll report back when I have news. |
Using your findings (thanks!), I was able to eliminate the |
Awesome. Is there any quick way to test it to see if it makes any difference to the queries hanging issue? I fear they're unrelated, since this started in |
@andreialecu Quick way to test:
That should install |
@benjamn unfortunately the bug in the OP still exists in Notice how As mentioned previously, the issue started between Alternatively, if you have any suggestions where to set any breakpoints and what to inspect, that would also be great. |
I noticed the same issue in |
@andreialecu A few more questions:
|
I am also having this issue. Some queries hang are never dispatched with Last version I can get to work with my Don't have time to put together a repro - also it seems intermittent - but can answer questions if it helps... |
@andreialecu Are you also using @bentron2000 Even if |
Yep, I'm using batching, see my comment above. I'm using
|
I'm using React fwiw. I'll watch and see what happens rather than clogging things up with a new issue for now. Will keep watching and commenting on solutions tho. |
wow i'm glad I found this I was starting to think I was going insane 😄 useLazyQuery is hanging for us as well while using the most recent alpha-6 |
I don't think what we were experiencing is a bug but a side effect of the change ... I appears I was not using useLazyQuery correctly in relation to my centralized contextProvider which oddly worked before the switch to 3.6.2+ and the alphas ... we switched to alpha-6 to solve the After re-ordering some things on my end to a HLC context provider ... requests started happening again but alpha-2 ( i had downgraded until useLazyQuery worked again ) was returning partial results on the first handful of queries ... eventually completing after subsequent runs, almost like it was returning early ditching out of data recieve ( cache issues ? ) ... after re-upgrading to alpha-6 everything started working correctly, which is good because now I can sleep again. |
Is there any update on the issue? I have not been able to upgrade from |
I also have hanging queries as described in this issue. Some details:
This has been especially hard to debug because I haven't been able to reproduce it in a dev environment. I'm only able to reproduce it when deploying my app to a production-like environment. Then, when I try to attach a debugger to the box, I'm no longer able to reproduce it 😵 Afaict, this is the only issue blocking me from upgrading to v3.6, which is the only thing blocking me from using certain React 18 features. It's also unclear to me whether all the behaviors described by folks in this issue are indeed the same issue. If it would be helpful for me to create a separate issue, or if there's any other info I can provide, please let me know 🙏🏻 |
@jdmoody I appreciate all the details, and while I share your uncertainty about how many different issues we're talking about here, I think there must be something wrong with |
Hello, I have tried 3.6.6 which potentially resolves a possible cause for this issue (#9718) but after some testing the issue is still present. As everyone else, we are also using |
I am not sure if it is related. We've recently upgraded from apollo v2 to apollo v3 (latest version). If I import the old We downgraded to 3.5.10 and it seems to work as expected. |
Alright, I believe this regression stems originally from PR #9248, which made the batch link capable of cancelling in-flight batched operations when the underlying observable is terminated. This theory about the source of the regression is consistent with @andrew-hu368's comment about the old While I am open to making the changes from PR #9248 more purely opt-in, I believe my PR #9793 fixes the problem without completely abandoning #9248. @andreialecu @jdmoody @bentron2000 @doflo-dfa @nikhilgupta16 @vieira @andrew-hu368 (and anyone else I missed) Please try running If that doesn't work, please try |
Run some e2e tests on 3.7.0-beta.3 and they are all green. Thanks for the update @benjamn |
I did some testing on Thanks Ben! |
Can also confirm that beta.3 seems to work. I just changed to Then upgraded to Seems fixed. Feel free to close the issue after releasing it to stable, or at your convenience. Thanks @benjamn! |
I also did the comparison between |
PR #9793 was first released in v3.7.0-beta.3 for testing, and now (in this PR) will be backported to the `main` branch, to be released in the next v3.6.x patch version, fixing a `BatchHttpLink` regression introduced in v3.6.0 that silently discarded some pending queries. Evidence this worked: - #9773 (comment) - #9690 (comment) - #9690 (comment) - #9690 (comment) - #9690 (comment)
Thanks for the confirmations everyone! This should now be fixed if you run |
Hurrah , 3.6.9 fixes it |
Intended outcome:
Queries should be dispatched to the network.
Actual outcome:
Queries are not dispatched to the network, they just hang.
While using
apollo-angular@3.0.1
with@apollo/client@3.6.x
it appears that some queries start hanging after a while.I'm also using graphql-code-generator to generate an apollo-angular data service, so usage looks like this:
After a while (within 1-2 minutes), the subscribe block will not be called any more. This can also be used with
rxjs
'sawait firstValueFrom(...)
and the promise will never resolve.Downgrading to
3.6.23.5.10 seems to fix the problem.How to reproduce the issue:
Unfortunately no repro, but hopefully it might be easy to pinpoint what would affect these by comparing
3.6.2 to 3.6.3.3.6.0 and 3.5.10.Versions
The text was updated successfully, but these errors were encountered: