Skip to content
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

Socket is closed even though there are pending subscriptions #66

Closed
rpastro opened this issue Nov 12, 2020 · 5 comments · Fixed by #67
Closed

Socket is closed even though there are pending subscriptions #66

rpastro opened this issue Nov 12, 2020 · 5 comments · Fixed by #67
Labels
bug Something isn't working released Has been released and published

Comments

@rpastro
Copy link
Contributor

rpastro commented Nov 12, 2020

I'm using graphql-ws together with Apollo client.

I noticed that for queries and mutations the cancellerRef.current is being invoked twice. Once when the Complete message is received and again from the cleanup function.

As a result state.locks gets decremented twice for the same operation, which causes the socket to be closed even though there are pending operations.

@enisdenjo
Copy link
Owner

Hmm, are you sure? I reckon this test would be failing then because of the double decrement:

it('should disconnect on last unsubscribe when mode is enabled', async () => {
const { url, ...server } = await startTServer();
const client = createClient({
url,
lazy: true, // default
retryAttempts: 0,
});
await server.waitForClient(() => {
fail('Client shouldnt have appeared');
}, 10);
const sub1 = tsubscribe(client, {
operationName: 'PingPlease',
query: 'subscription PingPlease { ping }',
});
await server.waitForOperation();
const sub2 = tsubscribe(client, {
operationName: 'Pong',
query: 'subscription Pong($key: String!) { ping(key: $key) }',
variables: { key: '1' },
});
await server.waitForOperation();
sub1.dispose();
await sub1.waitForComplete();
// still is connected
await server.waitForClientClose(() => {
fail('Client should have closed');
}, 10);
// everyone unsubscribed
sub2.dispose();
await server.waitForClientClose();
});

Maybe the test is flawed? 🤔

@rpastro
Copy link
Contributor Author

rpastro commented Nov 12, 2020

The problems happens with queries and mutations where the server sends the Completed event. What I noticed, at least with Apollo, is that the cleanup function gets invoked almost at the same time which causes the cancellerRef.current to be called twice for the same subscription.

@rpastro
Copy link
Contributor Author

rpastro commented Nov 12, 2020

BTW, this is the cleanup function I'm referring to.

      return () => {
        cancellerRef.current?.();
      };

@enisdenjo
Copy link
Owner

Ah, I follow. I was thinking about the canceller cleanup, the one in it haha.

Nevertheless, you're right, it can sure happen. I'll head over to your PR. 😄

@enisdenjo enisdenjo added the bug Something isn't working label Nov 12, 2020
@enisdenjo
Copy link
Owner

🎉 This issue has been resolved in version 1.13.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@enisdenjo enisdenjo added the released Has been released and published label Nov 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released Has been released and published
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants