vic / apollo-phoenix-websocket

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

React Native suspend&resume #12

Closed G3z closed 7 years ago

G3z commented 7 years ago

I'm using this in conjunction with react-native and everything was smooth until i tested a release build on my phone: When the app is suspended and resumed after a while (30s) it crashes. I have trouble identifying the source but here is the log

<Notice>: TCP Conn 0x1701834d0 SSL Handshake DONE
Apr  8 16:31:44 doStuff(CFNetwork)[1821] <Notice>: TIC TLS Event [3:0x170184440]: 20, Pending(0)
Apr  8 16:31:44 doStuff(CFNetwork)[1821] <Notice>: TIC TCP Conn Event [3:0x170184440]: 8 Err(0)
Apr  8 16:31:44 doStuff(CFNetwork)[1821] <Notice>: TIC TLS Handshake Complete [3:0x170184440]
Apr  8 16:31:44 doStuff[1821] <Notice>: tried to join multiple times. 'join' can only be called a single time per channel instance
Apr  8 16:31:44 SpringBoard[1493] <Notice>: Destination SBNotificationBannerDestination is now ready to receive notifications
Apr  8 16:31:44 doStuff[1821] <Notice>: Unhandled JS Exception: tried to join multiple times. 'join' can only be called a single time per channel instance
Apr  8 16:31:44 apsd(PersistentConnection)[90] <Notice>: 2017-04-08 16:31:44 +0200 apsd[90]: __dumpLogsForInconsistencyIfNecessary - lastBecameInconsistentTime 0.000000  sBecameInconsistentTime 0.000000  logDumpReason (null)
Apr  8 16:31:44 doStuff(CoreFoundation)[1821] <Notice>: *** Terminating app due to uncaught exception 'RCTFatalException: Unhandled JS Exception: tried to join multiple times. 'join' can only be called a single time per channel instance', reason: 'Unhandled JS Exception: tried to join multiple times. 'join' can only be ca..., stack:
i@65:234
u@64:1084
reportFatalError@5:186
<unknown>@19:136
value@19:810
'

my best guess is that tried to join multiple times. 'join' can only be called a single time per channel instance refers to this call in APW

this is how i have set up my Network Interface


let networkInterface = createNetworkInterface({
    uri: 'wss://my-phoenix-app.herokuapp.com:443/socket'
});

networkInterface.use([{
    applyMiddleware(req, next) {
        // get the authentication token from local storage if it exists
        const token = credentials_store && credentials_store.data && credentials_store.data.token;
        req.options.channel = req.options.channel || {};
        req.options.channel.topic = token ? "gql:query" : 'gql:login';
        req.options.channel.params = token ? { guardian_token: token } : null;
        next();
    }
}]);
G3z commented 7 years ago

i confirm that if the exception is handled (for example with a .catch attached to your promise) the app no longer crashes

vic commented 7 years ago

Hey @G3z thanks for opening this issue, haven't used this on react-native but your problem sounds like when the app is resumed, the channel is somehow already joined. If you have made it work for you, would be so kind to supply a pull-request ?

Thanks a lot :)

vic commented 7 years ago

Hey @G3z would it be possible for you to try the #13 branch and confirm that it works for your react-native app ? I've added a new test for rejoining the channel as described by this issue, but just want to be sure it works on your real case.

vic commented 7 years ago

Please upgrade to version 0.5.0

G3z commented 7 years ago

With the update no more crashes on resume: thanks