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

Auth token refresh misses when macOS is sleeping #984

Closed
SpencerCDixon opened this issue Feb 11, 2020 · 5 comments · Fixed by #986
Closed

Auth token refresh misses when macOS is sleeping #984

SpencerCDixon opened this issue Feb 11, 2020 · 5 comments · Fixed by #986
Assignees

Comments

@SpencerCDixon
Copy link

SpencerCDixon commented Feb 11, 2020

Which version of the Ably SDK are you using?

1.1.18

On which platform does the issue happen?

macOS 10.14.6

Are you using Carthage?

0.34.0

Which version of Xcode are you using?

Xcode 11.3
Build version 11C29

What did you do?

authCallback is not properly re-fetching TokenRequests when the computer is sleeping during the TTL expiration. Reproduction steps:

  1. Create TokenRequests returned from servers with TTL of ~2 minutes
  2. Set up client with auth options using the callback to get new TokenRequests
        let options = ARTClientOptions()
        options.authCallback = { tokenParams, complete in
            self.apiService.authenticateAbly { (response, error) in
                if let response = response {
                    do {
                        let parsed = try ARTTokenRequest.fromJson(response.tokenRequest as ARTJsonCompatible)
                        complete(parsed, nil)
                    } catch let error as NSError {
                        complete(nil, error)
                    }
                } else {
                    complete(nil, error)
                }
            }
        }
        options.clientId = "\(authInfo.id)"

        let ably = ARTRealtime(options: options)
  1. Put your computer to sleep and wait for >2min
  2. Watch as the client enters an infinite disconnect -> suspend loop and never tries to refetch TokenRequests properly.

Note: if you don't sleep the computer it refetches the tokens fine!

What did you expect to happen?

Client to properly reconnect once computer wakes from sleep.

What happened instead?

It never fetches the new token and enters this infinite loop of being unable to reconnect.

Edit: My guess is this issue is very related to this one

@QuintinWillison
Copy link
Contributor

Hello @SpencerCDixon - I appreciate the report and thank you for your time in investigating from your end. I'm asking our Cocoa developers, including @ricardopereira who worked on #881, to take a look in case there's something obvious to ask or point out.

@SpencerCDixon
Copy link
Author

Great, thanks! I chatted with Tom in Intercom and we went through a number of settings and flows that didn't work out. He may have some useful context to the situation.

Happy to recreate and capture verbose or debug logs if yall think that would be helpful as well!

@tcard tcard self-assigned this Feb 12, 2020
@tcard
Copy link
Contributor

tcard commented Feb 13, 2020

Hi @SpencerCDixon . The changes at branch 984-fix-token-error-connect fixed the issue in my repro. May I ask you to test it? Your Podfile should look like this:

pod 'Ably', :git => 'https://github.com/ably/ably-cocoa.git', :branch => '984-fix-token-error-connect'

Thanks!

@SpencerCDixon
Copy link
Author

Looks good to me on that branch! Thanks @tcard! Will that be able to make it into next release?

@QuintinWillison
Copy link
Contributor

That's great news. Nice work, @tcard.
@SpencerCDixon, thanks for letting us know that it works for you.

Toni's created a PR (#986) so as soon as we've merged that then either I or one of my colleagues will get a release out. Probably tomorrow at some point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants