-
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
Problem in unsubscribe of useSubscription react hook #7964
Comments
|
@zrcni I know that, But it doesn't |
I have created a test project for both client and server, Check it out: https://github.com/reza-ebrahimi/TestSubscrtiptionBug |
It seems Thanks @sunli829 |
We are seeing this in our application as well with lots of leaked subscriptions when using the |
I was wondering why the "stop" event was not being sent to my server, and it seems this is why! Seems like an issue, since it could potentially keep dozens of subscriptions open that are not actually used by the client anymore. (eg. if the user is moving between lots of different pages, each with their own sets of subscriptions) |
So I've looked into this a bit more, and the path that is taken from the user calling Here is the path that is taken:
I unfortunately could not definitively locate the definition of the Which calls The latter of which appears to call this cleanup function here (back up in the apollo-client/src/utilities/observables/Concast.ts Lines 216 to 239 in a565fd5
If you read through the Now the comment makes it sound like it's not the cleanup function's role to do that unsubscribing. But the issue is that nowhere in the apollo-client/src/utilities/observables/Concast.ts Lines 207 to 210 in a565fd5
But maybe the base There are some lines in it that call At this point, this is getting too complex for me to follow, so I've given up for now. If someone could continue the investigation, it would be appreciated. (perhaps one of the apollo-client maintainers?) For anyone wanting to take that journey, I think this is the "finish line" where you want the unsubscribe calls to end up: That apollo-client/src/link/ws/index.ts Line 42 in a565fd5
And each request (which starts a subscription) passes through that apollo-client/src/link/ws/index.ts Line 50 in a565fd5
Which is called by apollo-client/src/link/core/ApolloLink.ts Line 70 in a565fd5
Which is called by those lines referenced earlier (these two blocks) in So from the above, we have a rough idea of what the pathway is; but it was not clear to me from reading through it exactly where the issue is. That said, my guess is that the problem is somewhere in either apollo-client's Concast.ts or zen-observable's Observable.js. |
I was about to read through the test files to check whether there are tests set up (to confirm that And I saw it has 5,881 lines. And I quietly backed away. |
@benjamn Hey, I have the same problem Upgrading to 3.7.0-beta.1 did not help :( |
I'm a bit confused tbh, because just now I went to check the dev-tools WebSocket events for my website, and I am not currently seeing the issue I saw earlier, of the "stop" event never being sent. My guess is that, for my website, the issue came about due to some higher-level issue that ended up getting resolved from the other changes I've made in the last few months. So unfortunately, I can't confirm whether your patch resolves my original issue. That said, I notice three people upvoted the comment above saying the problem still exists for them. Maybe one of them has a reproduction repository that they can share? |
Having the same issue here: Subscriptions not re-subbing when device is locked :(( |
for what it's worth since I found this through google - though there are mixed opinions online (eg. #7964 (comment), this SO post) about whether or not In my use-case I was using useEffect(() => {
const unsub = subscribeToMore({ ... your options })
return () => unsub()
}) I don't know why the docs don't mention this. https://www.apollographql.com/docs/react/data/subscriptions/#subscribing-to-updates-for-a-query using apollo-client |
Same issue, useSubscriptions is not resubbing after device is locked. I use expo with apollo-client v3 and hasura as backend. |
I experience the same problem 🙁. Refreshing React app with subscriptions active doesn't send |
As far as I can tell, this would only ever occur when used in combination with React's @jazithedev @reza-ebrahimi @ghempton @Venryx would anyone be able to either corroborate that We have a CodeSandbox and forkable GitHub repo with a |
@alessbell I'm also seeing this error outside of strict mode. In my case I have added debug logs to make sure the component is unmounted but I still get updates from the unmounted component. There seems to be a problem with the subscription endpoint(https://uifesi.sse.codesandbox.io/graphql) so I can't try to recreate the scenario in the sandbox. |
Hello. Any updates on this? I have a similar problem with the socket not closing its connection after the user closes or reloads the screen. The problem I'm facing is that those loose connections are piling up in the ApolloServer until the point where ApolloServer struggles to respond requests and fails. Is there a way to handle loose connections from ApolloServer? |
The next minor release of Apollo Client will come with a rewrite of What @HelaGone mentions here with subscriptions staying open after a screen reload seems like it would be outside of our control here - are you talking a full app restart/browser refresh? |
Yes it is on full reload when I see that the socket never closes/completes. However I've seen that many other sites that use web sockets heavily have the same behavior. That's what makes me wonder if those loose connections should be managed by the server instead? |
On a full reload, the browser will just stop all JavaScript on the site, so there's not much "disconnecting" logic we can add, I fear. That said, it's also up to the browser to close open connections, so either your browser has a bug (which is very unlikely), or the connection is closed correctly, but for some reason your server doesn't register that. I'd investigate your server here. |
Version 3.11 has been released with a rewrite of If you find any problems with |
Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
When react component
unmounts
, theuseSubscription
hook doesn'tunsubscribe
stream in server side.The text was updated successfully, but these errors were encountered: