-
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
Inifinite loop when subscriptions go over HttpLink / when WebSocketLink is missing #7780
Comments
Bump I am experiencing a similar issue with |
Hey y’all! Just wanted to say thank you for opening the issue and providing a reproduction. I will try to investigate and get back to you on this by end of day Friday 🤞 (I just started at Apollo, so I currently have a lot of things on my plate in terms of ramping up, sorry). |
Should be fixed by #7917. Thanks again for the reproduction! It was very helpful in tracking down the cause. Should be shipped in the next minor release. Also opened another issue (#7950) to track Please feel free to ping me if you have any questions or concerns, or reopen the issue if you’re still having trouble. |
Intended outcome:
No infinite loop / crash when subscriptions are executed using HttpLink
This issue became apparent with a specific interaction between login/logout and our apollo client initialization logic / instance caching. Root cause being a missing websocket / split link, and useSubscription hooks executing in that context. At least doesn't seem useful to enter into a loop, ideally it would execute at most once, or not at all (error seems appropriate), or at least warn about the issue (a graphql subscription executing over http).
Actual outcome:
Infinite render loop until crash
How to reproduce the issue:
Minimal reproduction: https://codesandbox.io/s/apollo-subscriptions-http-link-infinite-loop-dqg06
Open "Without issue" link, subscriptions run over websocket, everyone is happy :)
Open "With issue" link, subscriptions run over http, causing render loop and crash, sad :(
Larger reproduction, a bit more similar to actual environment where this originally came up: https://codesandbox.io/s/r5skw?file=/pages/signin.js
Need to comment out the "fix" on line 40 to show the issue, sign in using any token, and it'll use the apollo client that was initialized in the sign in page (has no websocket because of missing token / user session), so opening the chat page causes an infinite render loop. If you instead refresh before you open the chat page, it'll create an apollo client in a context where a token is defined and the init logic will thus create a wsLink, and the chat page will work using ws as it should without looping. Similarly, if one opens the chat page and the issue causes the tab to crash, refreshing/reopening the chat page while a token cookie is set allow the happy path of having a websocket to run.
/pages/signin.js line 39-40
I guess it's possible to use server sent events somehow to enable subscriptions over http with apollo, but at least for what I assume is the most common use case, a WebSocketLink is likely to be expected when executing graphql subscriptions. It's quite obvious that a subscription wouldn't work correctly over plain http at least, but not necessarily so obvious to find the underlying cause / fix. Seems it would be most helpful with at least a warning in development if this happens.
Versions
(Latest on CodeSandbox)
System:
OS: Linux 5.4 Debian GNU/Linux 10 (buster) 10 (buster)
Binaries:
Node: 10.23.0 - /usr/local/bin/node
Yarn: 1.22.10 - /usr/local/bin/yarn
npm: 6.14.8 - /usr/local/bin/npm
npmPackages:
@apollo/client: 3.3.11 => 3.3.11
apollo-server-micro: 2.21.0 => 2.21.0
The text was updated successfully, but these errors were encountered: