Giter Club home page Giter Club logo

Comments (26)

nuno-vieira avatar nuno-vieira commented on June 9, 2024 1

btw @kirsanov-dev , I can see that in your logout() function you are not logging out from Stream, you just disconnect the user. You need to call streamChat.logout() and not disconnect in this case, and ideally wait for the completion block.

from stream-chat-swift.

nuno-vieira avatar nuno-vieira commented on June 9, 2024 1

@kirsanov-dev Yes, under the hood it disconnects and cleans the internal DB which is the most important thing here. So you only need to logout, internally we already disconnect too.

from stream-chat-swift.

oleg-rocks avatar oleg-rocks commented on June 9, 2024 1

Thanks for explanation. I will add logout to our implementation. I'll post update tomorrow. Maybe it will resolve this issue.

from stream-chat-swift.

testableapple avatar testableapple commented on June 9, 2024 1

@kirsanov-dev, thanks for checking the branch. we're glad it solved the crash for you. It was a proof of concept to detect a place where the issue might be. We will share an update here as soon as it will be fixed and released. The PR will be linked to this issue.

Regarding the SwiftUI-related issue, please report it to https://github.com/GetStream/stream-chat-swiftui.

from stream-chat-swift.

testableapple avatar testableapple commented on June 9, 2024 1

Hi @kirsanov-dev, we were able to reproduce the issue with unread counter on our side, it's a bug in LLC, so no need to report it to a SwiftUI-related repo. We're investigating it and will keep you posted.

from stream-chat-swift.

nuno-vieira avatar nuno-vieira commented on June 9, 2024 1

Hi @kirsanov-dev!

Just to let you know, the 2 fixes will be available in the next 4.50.0 release 👍 ETA is next week.

Best,
Nuno

from stream-chat-swift.

testableapple avatar testableapple commented on June 9, 2024

Hi @kirsanov-dev,
Thanks for opening the issue.

Unfortunately, I was not able to reproduce it on our side. Could you clarify something, please:

  • Could you share the crash log?
  • Could you also share the code snippets on how you're doing the logout? In particular I'm interested if you're waiting for the completion block of the logout function.
  • Could you also share how you are creating the ChatClient? Do you destroy the ChatClient at any point?
  • Do you have Background Mapping enabled?
  • Could you check out 4.49.0? We had some regression in 4.48.0. Even though that one is not related, it's worth trying the latest release, just in case.

Best,
Alexey

from stream-chat-swift.

oleg-rocks avatar oleg-rocks commented on June 9, 2024

Hi @testableapple

  1. Couldn't find crash logs. Only this in the console
2024-02-28 18:43:39.008 [ERROR] [io.getstream.logger] [ListDatabaseObserver.swift:258] [startObserving()] > Assert failed: Unable to convert a DB entity to model: ChannelReadDTO object with ID 0xef2919ff575564f2 <x-coredata://4E991088-F4FE-46FA-B610-EC44158F8D07/ChannelReadDTO/p149> is invalid
StreamChat/ListDatabaseObserver.swift:260: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
// Close the WebSocket connection when component dismounts
    func disconnectUser(completion: (() -> Void)? = nil) {
        chatClient.disconnect {
            completion?()
        }
    }

    func logout() {
        // Since we don't need the result of logout() response we call subscribe() right here
        _ = authRepository.logout().subscribe()

        if let _ : Bool = try? Dependencies.standard.persistenceStorage.getValue(storageType: .userDefaults, key: HfConstants.UserDefaults.hasSignedInWithSSO) {
            ssoManager.logOutUser()
        }

        clearAuthValues()
        clearStorageValues()
        analyticsManager.reset()
        pushNotificationsManager.removeAllPendingNotifications()
        remoteImageManager.clearCache()
        chatManager.disconnectUser {}
    }
  1. No, the client is created only once on the app launch. It's never destroyed. User is disconnected on profile (instance) change or logging out. On logging out we don't pass anything to the completion block.
final class Chat {
    static var shared: Chat = {
        return Chat()
    }()

    private(set) var client: ChatClient

    private init() {
        guard let path = Bundle.main.path(forResource: "Config", ofType: "plist"),
              let dict = NSDictionary(contentsOfFile: path),
              let apiKey = dict["streamChatApiKey"] as? String else {
            fatalError("Stream chat API key not found in Config.plist")
        }

        let config = ChatClientConfig(apiKey: APIKey(apiKey))
        client = ChatClient(config: config)
    }
}
  1. No background mapping used.
  2. We'll try to reproduce these steps on 4.49.0. Please, review my answers. Could there be any useful information?

from stream-chat-swift.

nuno-vieira avatar nuno-vieira commented on June 9, 2024

Hi @kirsanov-dev,

Do you have any customization of the Channel List that you can share with us? Since we can't reproduce in our side, it could be related to an issue in your integration.

Best,
Nuno

from stream-chat-swift.

oleg-rocks avatar oleg-rocks commented on June 9, 2024

We didn't customize this list. I have just tried to reproduce it and discovered that the easiest way to do it is to create a direct message group with a person who has absolutely no chat history. Absolutely new user. The app should crash on this new user's side.

from stream-chat-swift.

nuno-vieira avatar nuno-vieira commented on June 9, 2024

Hi @kirsanov-dev,

We just tested this, and it seems to work fine. How are you creating these channels? Can you share the code?

Here is our demo working:

NoCrash.mov

from stream-chat-swift.

oleg-rocks avatar oleg-rocks commented on June 9, 2024

There's one slight difference from your demo. I reproduce the issue when I create a dircect 1:1 message without a name. So the name parameter here is set to nil. Here's how we create direct message chat with one or multiple users.

    func makeChannelController() throws {
        let selectedUserIds = Set(selectedUsers.map(\.id))

        channelController = try chatClient.channelController(
            createDirectMessageChannelWith: selectedUserIds,
            type: .messaging,
            extraData: [:]
        )

        guard let channelController else { return }

        channelController.synchronize { [weak self] error in
            guard let self else { return }
            if error == nil {
                self.selectedUsers = []
                self.makeChannelInfo()
                self.state = .channel
            } else {
                self.state = .error
            }
        }
    }

from stream-chat-swift.

testableapple avatar testableapple commented on June 9, 2024

@kirsanov-dev, just to confirm, if you create a chat via sending a message, will the app crash?
Even though it should not be an issue and we tested this in our Demo app as well, but creating an empty 1:1 chat (not a group with two members) is not a quite common usecase 🤔

from stream-chat-swift.

nuno-vieira avatar nuno-vieira commented on June 9, 2024

There's one slight difference from your demo. I reproduce the issue when I create a dircect 1:1 message without a name. So the name parameter here is set to nil. Here's how we create direct message chat with one or multiple users.

    func makeChannelController() throws {
        let selectedUserIds = Set(selectedUsers.map(\.id))

        channelController = try chatClient.channelController(
            createDirectMessageChannelWith: selectedUserIds,
            type: .messaging,
            extraData: [:]
        )

        guard let channelController else { return }

        channelController.synchronize { [weak self] error in
            guard let self else { return }
            if error == nil {
                self.selectedUsers = []
                self.makeChannelInfo()
                self.state = .channel
            } else {
                self.state = .error
            }
        }
    }

@kirsanov-dev It should be fine, the name is nil by the default, so the issue is not related with that.

from stream-chat-swift.

oleg-rocks avatar oleg-rocks commented on June 9, 2024

@testableapple no, the app crashes instantly after the chat creator presses the create button. As I already mentioned, the issue can occur without any actions from the iOS user. An Android user can cause it by creating a new 1:1 chat. The main conditions are: new user with no chat history, 1:1 chat with nil name, and an open chat list screen on iOS user's side.

from stream-chat-swift.

oleg-rocks avatar oleg-rocks commented on June 9, 2024

@nuno-vieira does logout method contain disconnection under the hood? If I change user's instance inside the app without logging out, do I have to disconnect AND logout OR only logout? New instance means the same email for login but a different employer, another set of permissions and definitely another set of visible chats and channels.

from stream-chat-swift.

oleg-rocks avatar oleg-rocks commented on June 9, 2024

The issue still exists. Steps to reproduce:

  1. Log out using the client.logout { } method.
  2. Log in as another user without closing the app. The same api key. Name, user id and token are different.
  3. On successful login, connect using the client.connectUser { } method.
  4. Open the chat list screen -> the list is updated according to the new user.
    Using non-customized built-in component.
                        ChatChannelListView(
                            viewFactory: viewModel,
                            onItemTap: { channel in
                                viewModel.didPressChannel(
                                    channel: channel,
                                    scrollToMessage: nil
                                )
                            },
                            embedInNavigationView: false
                        )
  1. From another phone create a new 1:1 chat with this new user -> the app crashes on new user's phone.

2024-02-29 17:03:43.893 [ERROR] [io.getstream.logger] [ListDatabaseObserver.swift:258] [startObserving()] > Assert failed: Unable to convert a DB entity to model: ChannelReadDTO object with ID 0xdcfd06bdbaef03b2 x-coredata://AA2B30F8-DAA7-419D-8387-9A4007B97D5E/ChannelReadDTO/p1054 is invalid
StreamChat/ListDatabaseObserver.swift:260: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

It seems like there's a conflict in the internal database. This issue never occurs when logging out and then logging back in as the same user.

Please recommend where the root of the problem could be.

from stream-chat-swift.

testableapple avatar testableapple commented on June 9, 2024

Hi @kirsanov-dev,

Some additional questions:

  • Does it also happen on iOS + iOS clients or only when the chat was created on Android?
  • If you add a name to the channel, will it still crash?
  • Do you have any issues creating the channel? Can you add a breakpoint or print an error if it pops up?:
            controller.synchronize { [weak self] error in
                if let error = error {
                    print(error.localizedDescription)
                    return
                }

                // ...
            }

from stream-chat-swift.

oleg-rocks avatar oleg-rocks commented on June 9, 2024

@testableapple

  1. It may happen on both iOS+Android and iOS+iOS.
  2. We haven't implemented named channels yet, so I can't test this.
  3. Added the print statement to synchronize block but didn't catch any errors on creator's phone.

from stream-chat-swift.

testableapple avatar testableapple commented on June 9, 2024

@kirsanov-dev,

  • Can you confirm that the crash does not occur if the user has other channels?
  • Can you confirm that the crash does not occur if the user creates a channel via sending a message (the way it works on, for instance, WhatsApp)?

from stream-chat-swift.

testableapple avatar testableapple commented on June 9, 2024

@kirsanov-dev, could you please also sniff traffic (e.g. via Proxyman) and check if there is anything suspicious (https/websocket)? What does the participant's phone receive before the crash?

from stream-chat-swift.

nuno-vieira avatar nuno-vieira commented on June 9, 2024

Hi @kirsanov-dev,

Can you test this branch: fix/crash-in-startObserver-after-logout and see if it fixes it?

from stream-chat-swift.

oleg-rocks avatar oleg-rocks commented on June 9, 2024

@nuno-vieira The issue has been fixed with the changes in the branch fix/crash-in-startObserver-after-logout. Thank you! This issue can be closed. Will this fix be included in the next release?

P.S. I've noticed another issue: the unread counter briefly appears for a second after every new message and then disappears. Could this problem be related to the recent fix, or is it because I've updated the StreamChatSwiftUI pod to 4.49.0? The counter worked fine on version 4.48.0. Should I open a new issue in stream-chat-swiftui section?

Simulator.Screen.Recording.-.iPhone.14.-.2024-02-29.at.22.39.31.mp4

from stream-chat-swift.

nuno-vieira avatar nuno-vieira commented on June 9, 2024

@kirsanov-dev Thanks for testing it out. 🙏 Make sure that you don't have a user online on another device reading the channel. The Unread feature it is not changed, so it should work 🤔 But it should not be related to SwiftUI.

If you verified that nobody is reading the channel. Does the unread start working again, if you logout and login again?

Update: I was actually able to reproduce it, if you disconnect and login with a different user, the unread count won't work properly. Even tho the crash has been fixed, you still need to make sure you logout, and not disconnect, if your intent is to login with a different user.

from stream-chat-swift.

oleg-rocks avatar oleg-rocks commented on June 9, 2024

@nuno-vieira
I'm testing on the same fix/crash-in-startObserver-after-logout branch as yesterday.
I set a breakpoint on this line in the Stream source code
log.debug("Logging out current user successfully.", subsystems: .all)
in the method logout(completion: @escaping () -> Void).
It gets called on every logout event.
The logout method in the app calls only logout, not disconnect.

func logout() {
        _ = authRepository.logout().subscribe()
       ...
        chatManager.logout {}
        clearAuthValues()
        clearStorageValues()
        analyticsManager.reset()
        pushNotificationsManager.removeAllPendingNotifications()
        remoteImageManager.clearCache()
    }

The issue with the unread counter still occurs.
Log out as user A and re-enter as the same user A -> the unread counter works as usual.
Log out as user A and login as another user B -> the unread counter doesn't appear at all.
Log out as user A, login as user B, log out as B and re-enter to the original user A -> on every new message the unread counter appears for a moment and then disappears.

from stream-chat-swift.

testableapple avatar testableapple commented on June 9, 2024

Hey @kirsanov-dev,

Both fixes have been released as part of 4.50.0

Best,
Alexey

from stream-chat-swift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.