vic / apollo-phoenix-websocket

An Apollo networkInterface for executing GraphQL queries via Phoenix Channels
Apache License 2.0
91 stars 9 forks source link

Leave channel and clear queue on join error, socket error. #8

Closed conor-mac-aoidh closed 7 years ago

conor-mac-aoidh commented 7 years ago

@vic I've been doing some more testing the result of which is that we should be using leave when a channel join error or socket error occurs.

Without these lines, I have been getting some errors like:

EXCEPTION: tried to join multiple times. 'join' can only be called a single     
    time per channel instance

To recreate this error, you can simply start & stop the phoenix server. In the console, you should see the above error. This is the state the channel is in when the error occurs (extract from the debugger):

> chan.conn
Channelbindings: Array[3]
joinPush: Push
joinedOnce: true
params: Object
pushBuffer: Array[0]
rejoinTimer: Timer
socket: Socketstate: "joined"
timeout: 10000
topic: "gql:query"
__proto__: Object

> chan.conn.isJoined()
false
> chan.conn.isJoining()
false

Also, if the leave isn't executed, the client will continuously attempt to rejoin the channel - and keep failing if it is an auth problem.

Additionally, when an error occurs, the channel queue must be cleared, otherwise, these queries will be re-executed again later.

vic commented 7 years ago

Oh thank you so much for fixing this @conor-mac-aoidh, now leaving the channel makes sense. You can merge this when ready, looks right to me 👍

conor-mac-aoidh commented 7 years ago

@vic can you publish a new version? Thanks!

vic commented 7 years ago

@conor-mac-aoidh done! 0.4.2 is on npm.