parse-community / ParseLiveQuery-iOS-OSX

Parse LiveQuery Client for iOS/OS X.
https://parseplatform.org
Other
192 stars 133 forks source link

LiveQuery interrupted by external operation on the table it monitors on #247

Closed bayareahank closed 3 years ago

bayareahank commented 3 years ago

Observed a phenomenon on live query, not sure anybody here has seen something similar before.

Basically I liveQuery on a conversation table for a chat app. On receiving new conversations (new event) or existing conversation having new messages (update event), I will update the UI accordingly. Yet I observed that when I do some operation outside of liveQuery that change (mainly remove current user related record from) the conversation table, liveQuery would sometimes stop responding to live events. Interesting thing is it doesn't stop only with this conversation table liveQuery, all other liveQuery of the same app would stop working as well. Unsubscribe and resubscribe doesn't help in this case. Restart the app, or run Client.shared.reconnect() before doing liveQuery would make it work again.

Sample code look like this:

    listenQuery = PFQuery(className: "Listening")
        .whereKey("person", equalTo: profile.pfObject)

    let liveQueryClient = Client.shared
    // liveQueryClient?.reconnect()              // This is the work around. 

    subscription = liveQueryClient!
        .subscribe(listenQuery)
        .handleEvent({
            (_, event) in

            switch event {
            case .created(let object):
                guard let listen = Listening(listening: object) else {
                    return
                }

                self.newChatHandler(listens: [listen])

            case .updated(let object):
                guard let listen = Listening(listening: object) else {
                    return
                }

                self.updateExisting(listen)

            default:
                break
            }
        })
        .handleError({ (query, error) in
            os_log("startLiveQuery: error: %@", type: .debug, error.localizedDescription)
        })

I am not sure whether not handling delete event has anything to do with this. LiveQuery works fine without touching the DB table, or only adding to the table, and would only stop working (sometimes, not always) when a record is removed. This removal could come from user operation (by blocking a contact, thus removing a conversation), or triggered on the server side by other user, though I haven't pinpointed any exact repeatable source pattern.

I don't know whether anybody here has run into something similar. Reconnect before starting each liveQuery works to me, but doesn't look the right solution.

Setup:

github "BoltsFramework/Bolts-ObjC" "1.9.1" github "BoltsFramework/Bolts-Swift" "1.5.0" github "ParsePlatform/Parse-SDK-iOS-OSX" "1.19.1" github "ParsePlatform/ParseLiveQuery-iOS-OSX" "2.8.0" github "daltoniam/Starscream" "4.0.4"

Xcode 12.4 Swift 5.3.2

bayareahank commented 3 years ago

Update: Receiving a notification in the background mode will break the liveQuery also. In considering #248, it looks liveQuery is quite brittle in regard to network disturbance. I am not sure this project is still being maintained, hopefully the new parse-swift would work better.

TomWFox commented 3 years ago

Thanks for reporting. Unfortunately we don't currently have an active maintainer for this repo. If you would like to contribute any fixes and/or improvements someone from @parse-community/ios-osx-sdk may be able to review any PRs.

As you suggested parse-swift will likely supersede this package and is under very active development. I would definitely suggest you test it out if you haven't already!

bayareahank commented 3 years ago

Definitely, if it is stable enough :). Thanks for the hard work!