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

Failure to obtain token results in an infinite loop #3424

Open
pavermakov opened this issue Sep 18, 2024 · 5 comments
Open

Failure to obtain token results in an infinite loop #3424

pavermakov opened this issue Sep 18, 2024 · 5 comments
Labels
🐞 Bug An issue or PR related to a bug 🌐 SDK: StreamChat (LLC) Tasks related to the StreamChat LLC SDK

Comments

@pavermakov
Copy link

What did you do?

I have the following tokenProvider in my app:

private lazy var tokenProvider: TokenProvider = { [weak self] completion in
        _ = self?.authRepository.chatToken()
            .observeOn(MainScheduler.instance)
            .subscribe(
                onSuccess: { response in
                    if let chatToken = response.chatToken {
                        completion(.success(Token(stringLiteral: chatToken)))
                        do {
                            let decoder = JWTDecoder()
                            let jwtData = try decoder.decode(jwtToken: chatToken)
                            if let exp = jwtData["exp"] as? TimeInterval {
                                self?.tokenExpiryTime = exp
                                self?.tokenExpiryDate = Date(timeIntervalSince1970: exp)
                            }
                        } catch {
                            completion(.failure(AppErrors.generic))
                        }
                    } else {
                        completion(.failure(AppErrors.generic))
                    }
                },
                onError: { error in
                    completion(.failure(error))
                }
            )
    }

If the authRepository.chatToken() fails with, for example, a 401 error, the stream chat will start repeatedly calling the tokenProvider and failing.

Screenshot 2024-09-18 at 19 15 24

What did you expect to happen?

The completion handler of the connectUser to be called with an error. Or a way to break out of the loop.

What happened instead?

An infinite loop.

GetStream Environment

GetStream Chat version: 4.52.0
GetStream Chat frameworks: StreamChat, StreamChatUI
iOS version: 17.5.1
Swift version: 5.8.1
Xcode version: 15.3
Device: iPhone 12

@nuno-vieira
Copy link
Member

Hi @pavermakov,

This issue is already fixed on more recent versions. Please update the SDK to the latest version.

Thank you,
Nuno

@pavermakov
Copy link
Author

pavermakov commented Sep 21, 2024

Hi @nuno-vieira! Bumped version up to 4.63.0 and observed the same behaviour. The tokenProvider is called over and over again.

@nuno-vieira
Copy link
Member

Hi @pavermakov,

It is true, I can reproduce this. I will re-open it. We will let you know once we work on this issue. At the moment I can't provide you with an ETA.

Best,
Nuno

@nuno-vieira nuno-vieira reopened this Sep 23, 2024
@nuno-vieira nuno-vieira added 🐞 Bug An issue or PR related to a bug 🌐 SDK: StreamChat (LLC) Tasks related to the StreamChat LLC SDK labels Sep 23, 2024
@pavermakov
Copy link
Author

Thank you @nuno-vieira, I appreciate that! Also, I have noticed that the class AuthenticationRepository has constant maximumTokenRefreshAttempts set to 10. Is it possible to customise this value?

@nuno-vieira
Copy link
Member

nuno-vieira commented Sep 25, 2024

Hi @pavermakov, no, but you can provide a timeout through ChatClientConfig.reconnectionTimeout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 Bug An issue or PR related to a bug 🌐 SDK: StreamChat (LLC) Tasks related to the StreamChat LLC SDK
Projects
None yet
Development

No branches or pull requests

2 participants