Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Send INIT before SUBSCRIPTION_START #85

Merged
merged 5 commits into from
Mar 3, 2017

Conversation

timsuchanek
Copy link
Contributor

screen shot 2017-03-01 at 4 56 37 pm

Currently, the `SUBSCRIPTION_START` is being sent before the `INIT` message. In our case this results in `subscriptions-transport-ws` rejecting the `init_success` of the server. This only happens in rare cases and I could barely reproduce this. The environment that caused this problem looked like this: - Slow connection - Having 2 subscriptions in one application - Using the `react-apollo` client I'm not sure if the apollo client is responsible for the weird early `subscription_end`, but this is already a starting point.

Unfortunately, the test I added breaks 3 other Server related tests. Seems some async/concurrency issue, but I couldn't find out what exactly is causing it.
If it is ok for you, I also just can remove this test, as all other tests then still are green.
This is based on PR #84, so you might first merge PR #84.

@@ -243,6 +243,9 @@ export class SubscriptionClient {
this.eventEmitter.emit(isReconnect ? 'reconnect' : 'connect');
this.reconnecting = false;
this.backoff.reset();
// Send INIT message, no need to wait for connection to success (reduce roundtrips)
Copy link
Contributor

@NeoPhi NeoPhi Mar 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I isolate this MR to just moving where the INIT message is fired I'm not seeing any test failures. However the addition of the should send INIT message first test below introduces issues.

}
if (parsedMessage.type === SUBSCRIPTION_START) {
expect(initReceived).to.be.true
done()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to setup the client as a function variable and include a client.unsubscribeAll(); prior to calling done() otherwise the client will stick around and try to reconnect.

@timsuchanek
Copy link
Contributor Author

Thanks for the tip, just calling client.unsubscribeAll() right before calling done did the trick.

@NeoPhi NeoPhi merged commit 7dba040 into apollographql:master Mar 3, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants