Compacting Realm during getInstanceAsync causes listeners to stop working
Goal
When Realm.compactRealm() is called while Realm is being initialized (Realm.getInstanceAsync()), Realm is still opened, but no listeners get called afterwards.
Actual Results
I noticed this bug while using my application and, due to its services and compact workflow, I figured that compact could be the cause. Sometimes, after an update, the application wouldn't show any data.
Steps & Code to Reproduce
I have created a simplified Android project to reproduce the issue: https://github.com/jpmcosta/RealmTestProject/tree/e6b69172f3d5f77c122468092cd672da869bb37f
After opening the application, a list of items should be shown, but it is not. Plus, when the FAB is clicked, a new item should be created and added to the list, but that also doesn't happen.
It seems that there's an issue when something like this is called (and compact actually runs):
val realmAsyncTask = Realm.getInstanceAsync(realmConfiguration, realmCallback)
Realm.compactRealm(realmConfiguration) // This is causing an issue.
While realmAsyncTask finishes successfully and Realm is opened, no listeners get called afterwards.
The way I could consistently reproduce the issue was to ensure that the Realm file was always recreated. Otherwise, the issue stops happening, probably because compact is not doing anything.
Version of Realm and tooling
Realm version(s): 10.4.0
Realm Sync feature enabled: No
Which Android version and device(s): API 29 (emulator)
Hi @jpmcosta Thank you very much. This does indeed sound like a bug. I suspect we have a race condition in our internal datastructures that somehow gets out of sync in this case.