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

GQL subscription is using stale JWT after device idle (iOS) #21

Open
shyndman opened this issue Jun 7, 2021 · 4 comments
Open

GQL subscription is using stale JWT after device idle (iOS) #21

shyndman opened this issue Jun 7, 2021 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@shyndman
Copy link
Contributor

shyndman commented Jun 7, 2021

@MaxSchilling has reported that his graphql client is making a request using a stale JWT after the Android device has been off for some amount of time.

After some research, I suspect that Android Doze suspending timers and network connections. When the app resumes, the websocket notices and begins reconnecting with the old JWT, which happens concurrently with the JWT refresh.

I'm confirming now. If correct, the solution is simple, because the way gql_websocket_link is configured gives us control over socket creation, and that API is async — we can keep it waiting for a JWT refresh.

@shyndman shyndman self-assigned this Jun 7, 2021
@shyndman shyndman added the bug Something isn't working label Jun 7, 2021
@elitan
Copy link
Contributor

elitan commented Jun 7, 2021

We had a similar issue with the nhost-js-sdk.

This was our solution there:

https://github.com/nhost/nhost-js-sdk/blob/master/src/Auth.ts#L639-L650

@shyndman
Copy link
Contributor Author

shyndman commented Jun 7, 2021

Yes! I saw that while porting, and do have questions about that (since people are now building for Flutter Web.)

But in this case, it's not exactly the same issue.

What I'm seeing is Android suspending all network activity while "dozing" (a state that is entered after a few minutes of the screen being off). In this state, application code continues to run, which includes timer callbacks (possibly at a reduced or less exact rate), but network requests never go out (so JWTs don't refresh), and websocket keep alives never come in (leading to socket disconnects+reconnection attempts).

When everything wakes back up, it's in a bad state, because you have a websocket queued up to send its initial payload (which will contain the "current", stale, JWT), and a JWT refresh queued up that whose response won't be received before that payload is sent.

@MaxSchilling
Copy link

It actually also occured on iOS

@shyndman shyndman changed the title GQL subscription is using stale JWT after device idle (Android) GQL subscription is using stale JWT after device idle (iOS) Jun 7, 2021
@shyndman
Copy link
Contributor Author

shyndman commented Jun 7, 2021

Ah, well I believe it's even simpler in that case.

iOS standby mode is a lot like Doze from what I've read, but is even stricter. I should be able to repro the issues I've seen there with the same testbed.

Thank you for letting me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants