realm / realm-swift

Realm is a mobile database: a replacement for Core Data & SQLite
https://realm.io
Apache License 2.0
16.33k stars 2.15k forks source link

Sync realm Result.observe is not fired by remote change but on next write #7453

Closed jonathan-opuscope closed 3 years ago

jonathan-opuscope commented 3 years ago

How frequently does the bug occur?

All the time

Description

Using the tutorial task tracker app, the expected sync behavior (which is observed on the .NET and Android tutorial apps) is that when i make a change to a task in the backend the observe callback is called immediately on the client iOS SDK Results

What actually happens is that the observe callback is not called immediately. However if I change the status of another task on the iOS client, I get all the previous expected observe callbacks in one burst which seems to indicate that the sync occurred correctly but the callback was not called.

I might be doing something wrong as I'm not too familiar with the system but this is unchanged tutorial app, tried waiting for realm sync session connection and different ways of opening the realms but still observe the same behavior.

Stacktrace & log output

No response

Can you reproduce the bug?

Yes, always

Reproduction Steps

No response

Version

Realm 10.15.1 RealmDatabase 11.4.1

What SDK flavour are you using?

MongoDB Realm (i.e. Sync, auth, functions)

Are you using encryption?

No, not using encryption

Platform OS and version(s)

iPadOS 15.0

Build environment

Xcode version: 13.0 Dependency manager and version: Realm 10.15.1 RealmDatabase 11.4.1

tgoyne commented 3 years ago

I can reproduce this in the tutorial app, but when I try to reduce it to a test case it works.

jsflax commented 3 years ago

This is fixed by https://github.com/realm/realm-cocoa/pull/7455.

tgoyne commented 3 years ago

7455 does not do anything related to this. The tutorial app isn't using SwiftUI.

jsflax commented 3 years ago

Apologies, I confused this issue with #7447.

tgoyne commented 3 years ago

7447 is also probably the same root cause and not anything swiftui-related.

jsflax commented 3 years ago

Realising that now— though the Smalltalk app does work, so my fix must be a red herring.

tgoyne commented 3 years ago

I've successfully reproduced this in a reduced test case now. It's a race condition in asyncOpen and so only happens when that is used.

anton-plebanovich commented 3 years ago

In my case, the issue is that observation on the background thread fires only after forced realm.refresh() or on local changes. Example project - https://github.com/anton-plebanovich/SingleView/tree/327674397f998a1d668c56afd6322d4409f5f9d8

anton-plebanovich commented 3 years ago

It doesn't work for both jf/smalltalk - https://github.com/anton-plebanovich/SingleView/tree/327674397f998a1d668c56afd6322d4409f5f9d8 tg/sync-notifications - https://github.com/anton-plebanovich/SingleView/tree/7a7180ef60acb8e66429bb185c1ee93866fb74bc

anton-plebanovich commented 3 years ago

Actually, it doesn't work even if I pass DispatchQueue.main for a callbackQueue.

anton-plebanovich commented 3 years ago

Not reproducible on version v10.14.0 and introduced in version v10.15.0.

jumilla commented 3 years ago

The cause seems to be Realm Core

https://github.com/realm/realm-core/issues/4909

anton-plebanovich commented 3 years ago

Was it fixed?

leonidovia commented 3 years ago

Hello, this still doesn't work in version 10.18.0! If you connect to the existing realm, subscribe to changes to collections or objects, and then update something on another device or in the collection viewer in the Atlas - observe callback is not called. Is there any news on this?

anton-plebanovich commented 2 years ago

Looks fine on the latest 10.20.1 Realm - https://github.com/anton-plebanovich/SingleView/tree/bug/realm-observe

jeanbaptistebeau commented 2 years ago

Bug occurring in 10.22.0 for me. Has this been solved completely or not? #7456 mentions a bug in realm core.

jonathan-opuscope commented 2 years ago

We're getting the issue on the current

let coreVersionStr = "11.15.0" let cocoaVersionStr = "10.25.2"

8dorik commented 2 years ago

Hi guys! Using the latest 10.28.6 we are facing the same issue but in some particular circumstances. When we try the Realm.asyncOpen() and tasks.observe() for the first time everything is fine and the callback with changes is fired properly. But when we cancel the task and log out, doing the Realm.asyncOpen() + tasks.observe() for the second time, the issue occurs to happen. After the realm.refresh() the callback is fired but only once, so it doesn’t fix the problem for the next changes.