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

Timeout exceeded after socket reconnected #64

Closed
jamesholcomb opened this issue Aug 29, 2017 · 7 comments
Closed

Timeout exceeded after socket reconnected #64

jamesholcomb opened this issue Aug 29, 2017 · 7 comments

Comments

@jamesholcomb
Copy link

Steps to reproduce

  • Start server: DEBUG=* npm start
  • Open Android app, authenticate user, load some data utilizing services
  • Minimize app to background
  • Wait 30-60s for server debug log indicating socket is logged out: feathers-authentication:sockets:handler Successfully logged out socket with accessToken...
  • Restore app and perform something that instigates a service call
  • Exception thrown Timeout of 5000ms exceeded calling blah:find

I enabled debug() to track the feathers* logging in react native dev tools. Here are the important lines:

fetch:query Object {filter: "near", start: "2017-08-29T21:34:33.881Z", geoPoint: GeoPoint, maxDistance: 80450, sortDir: -1…}
feathers-socket-commons:client Sending socket.emit +2m (3) ["blah::find", Object, function]
feathers-authentication-client Socket reconnected +2m
feathers-authentication-client Socket authenticated! +71ms

Not sure if this is relevant, but the call to socket.emit happens before socket reconnected/authenticated event.

Alternatively, if I restore the app and wait 60s or so, the app will auto-reconnect, re-auth the socket and behave normally from there.

Expected behavior

The call to the service should not timeout

Actual behavior

Service call times out

System configuration

Tested using Android SDK 25 in emulator

Module versions (especially the part that's not working):

Client

"feathers": "2.1.6",
"feathers-authentication-client": "0.3.3",
"feathers-hooks": "~2.0.1",
"feathers-socketio": "~2.0.0",

Server

"feathers": "2.1.6",
"feathers-authentication": "1.2.7",
"feathers-authentication-hooks": "0.1.4",
"feathers-authentication-jwt": "0.3.1",
"feathers-authentication-oauth2": "0.2.3",
"feathers-configuration": "0.4.1",
"feathers-errors": "2.5.0",
"feathers-hooks": "2.0.1",
"feathers-hooks-common": "3.5.5",
"feathers-mongoose": "3.6.1",
"feathers-rest": "1.7.0",
"feathers-seeder": "1.0.8",
"feathers-socketio": "2.0.0",

React Native Version:
0.46.4

@jamesholcomb jamesholcomb changed the title Timeout exceed after socket reconnected Timeout exceeded after socket reconnected Aug 29, 2017
@jamesholcomb
Copy link
Author

@ekryski @daffl @marshallswain I'm stuck in the water on this one. I tried to work around it by doing an .authenticate() upon app resume from background, but still get a timeout.

Do you have any suggestions on how to gracefully reauthenticate the socket from the client if the server instigates the logout on a ping timeout?

@daffl
Copy link
Member

daffl commented Sep 18, 2017

Can you share the relevant part of your application setup? If the service calls are happening before authentication it might just be in the wrong place.

@jamesholcomb
Copy link
Author

jamesholcomb commented Sep 18, 2017

I believe the issue is that the service call (i.e. socket.emit) assumes there is a valid socket connection. When the app is suspended, the client does not receive any of the standard socket events (e.g. reconnect)...so it's trying to emit on a disconnected socket.

My temp hack is set set the timeout low and use AppState to restore the socket connection by reauthenticating. But I think this should ultimately be handled by the feathers auth client.

class Application extends React.PureComponent {
  @observable appState = AppState.currentState
  state = {
    loading: false
  }

  appStateListener = async (nextAppState) => {
    console.log("appState", nextAppState)
    if (
      this.appState.match(/inactive|background/) &&
      nextAppState === "active"
    ) {
      console.log("Reconnecting...")
      this.setState({ loading: true })
      // TODO https://github.com/feathersjs/feathers-authentication-client/issues/64
      try {
        await app().authenticate()
      } catch (e) {
        //swallow
      } finally {
        this.setState({ loading: false })
      }
    }

    this.appState = nextAppState
  }
}

@ekryski
Copy link
Member

ekryski commented Oct 17, 2017

@daffl I think @corymsmith and I had this issue on a previous app. We ended up having to mess with the socket timeout for every service on our RN app.

However, I think that was only before this PR landed. @corymsmith might have a bit more context.

@AndrewJDR
Copy link

I'm running into this as well.
Would this PR be helpful to fix it? #70
If so, I notice that PR has been stuck since Sept 2017... what needs to happen with it?

@daffl
Copy link
Member

daffl commented Jan 10, 2018

There was a discussion and nobody involved followed up on it. For React Native specifically there is documentation how to set the timeouts at https://docs.feathersjs.com/api/client.html#react-native

@daffl
Copy link
Member

daffl commented Apr 22, 2019

All reconnection issues should be fixed in Feathers v4 authentication. Please see the migration guide for more information. Closing this issue in order to archive this repository. Related issues can be opened at the new code location in the Feathers main repository.

@daffl daffl closed this as completed Apr 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants