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

Chat Client crashes upon initialization #954

Closed
39otrebla opened this issue Apr 5, 2021 · 5 comments · Fixed by #1026
Closed

Chat Client crashes upon initialization #954

39otrebla opened this issue Apr 5, 2021 · 5 comments · Fixed by #1026

Comments

@39otrebla
Copy link

What did you do?

I upgraded from version 3.1.1 to version 3.1.4 of the StreamChat SDK.

What did you expect to happen?

I expected to see new Channel properties working.

What happened instead?

App crashed upon client initialization. It does happen both with clean installs and installing over previous data (BTW, it seems that a CoreData migration is needed upgrading from 3.1.1, and the crash happens right after migrating).

Crash is in NSManagedObjectContext+Extensions:

extension NSManagedObjectContext {
    private static let localCachingKey = "io.getStream.StreamChat.local_caching_key"
    
    /// Provides the defaults for local caching and model serialization for this context.
    var localCachingSettings: ChatClientConfig.LocalCaching? {
        get { userInfo[Self.localCachingKey] as? ChatClientConfig.LocalCaching }
        set { userInfo[Self.localCachingKey] = newValue }
    }
}

The crash is a bad access: Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0), happening in the set hook.

GetStream Environment

GetStream Chat version: 3.1.4
GetStream Chat frameworks: StreamChat
iOS version: 14.4
Swift version: 5.2
Xcode version: 12.4
Device: both simulators and real devices

Additional context

It is happening 100% of the times, i.e. our app is completely stuck. Here is how we initialize it:

var config = ChatClientConfig(apiKeyString: apiKey ?? "")
config.baseURL = .dublin
config.shouldConnectAutomatically = false
config.shouldFlushLocalStorageOnStart = false
config.localCaching.chatChannel.lastActiveMembersLimit = 2
config.localCaching.chatChannel.lastActiveWatchersLimit = 2
config.localCaching.chatChannel.latestMessagesLimit = 10

client = MyChatClient(config: config, tokenProvider: .closure { chatClient, completion in
  // our token refresh implementation
  [...]

  self.client.connectionController().connect()
})
@VojtaStavik
Copy link
Contributor

@39otrebla Thank you for the bug report! The fact that the crash happens also for clean installations is important.

Would you mind sharing the full stack trace of the crash with me, please?

@VojtaStavik
Copy link
Contributor

Probably unrelated but I noticed that you set config.shouldConnectAutomatically = false and then call connect() explicitly from the token provider. That shouldn't be needed. The client calls the token provider first and doesn't try to connect until the completion of the provider is called with the new token.

Can you please confirm the crash still happens when you remove config.shouldConnectAutomatically = false and the explicit connect() call?

@39otrebla
Copy link
Author

39otrebla commented Apr 5, 2021

@VojtaStavik To reduce session-related stuff as much as possible I temporarily switched to "static" tokens, i.e. backend returns a StreamChat token without expiration upon user login (along with our own session data). No luck. It's still happening, here is the code.

private var clientConfig: ChatClientConfig?
private var apiKey: String? {
    didSet {
        clientConfig = ChatClientConfig(apiKeyString: apiKey ?? "")
        clientConfig?.baseURL = .dublin
        clientConfig?.shouldConnectAutomatically = true
        clientConfig?.shouldFlushLocalStorageOnStart = false
        clientConfig?.localCaching.chatChannel.lastActiveMembersLimit = 2
        clientConfig?.localCaching.chatChannel.lastActiveWatchersLimit = 2
    }
}

[...]

client = MyChatClient(config: clientConfig,
                                     tokenProvider: .static(tokenStruct),  // this token (exactly this one) works on 3.1.3
                                     completion: { error in
                                        guard error == nil else {
                                            // TODO
                                            return
                                        }
                                     })

@VojtaStavik
Copy link
Contributor

@39otrebla Thank you for more details. Can you please include the crash stack trace, too? On which thread is the ChatClient initialized?

@39otrebla
Copy link
Author

@VojtaStavik the ChatClient is initialized on the Main thread. It turned out to be the CoreData concurrency debug build argument, so it's not crashing in release builds.

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

Successfully merging a pull request may close this issue.

2 participants