Closed cfeckardt closed 7 years ago
So a preliminary update. It appears that downgrading to Realm 2.5.1 magically resolves the issue. (We picked 2.5.1, because that was the previous version we were running).
EDIT:
Spoke to soon. Downgrading gives a different crash (that appears to be much rarer):
We have found a workaround.
If we run the compaction only the very first time the realm is opened (after application start), we won't have an issue.
I suspect that the compaction code does not correctly determine whether there are other realms currently referencing the file, and the crash is caused by trying to open a file reference that has been modified/deleted by compaction?
I have checked instruments, and while there are no RLMRealms around at the moment of crash there were RLMResults and notification tokens hanging around in memory. Perhaps the engine incorrectly tries to compact it and does not take these file references into account?
Sounds like this might be related to #5010, which is being fixed in #5114. I'd appreciate if you could build Realm from that branch to see if it resolves your issue.
@jpsim yeah we can do that. I'll get a build out to our beta testers today, and should have a definitive answer on whether it worked or not by Monday.
Unfortunately #5010 Did not fix this issue for us.
You mean #5114, right? How are you building that? That branch (jp-skip-compact
) depends on a different submodule commit, so pulling that in is sometimes tricky.
It looks as if you're using CocoaPods, so your Podfile
should look something like this:
pod 'Realm', git: 'https://github.com/realm/realm-cocoa.git', branch: 'jp-skip-compact', submodules: true
pod 'RealmSwift', git: 'https://github.com/realm/realm-cocoa.git', branch: 'jp-skip-compact', submodules: true
I've also noticed that sometimes specifying a submodule in CocoaPods does not actually work as expected, so you should check the source files and make sure they've actually changed.
You can always delete CocoaPods' cache if it's using an older version of the branch: rm -rf ~/Library/Caches/CocoaPods
We have checked that we indeed ran the correct branch, and we did. We are currently refactoring the code so that we use realm from one thread only. Hopefully that sorts things out.
Well if there is a bug here that's not fixed by #5114, and you're working around it by changing your code to avoid the bug, we're not really advancing the product by doing so. Someone else is bound to run into it.
Unfortunately there's nothing we can really do about that until we can reproduce the bug ourselves, which is why we'd really appreciate a repro case from you @cfeckardt.
Thanks for your assistance.
Closing as there's nothing actionable left to do here and we haven't heard back from @cfeckardt.
Excuse the delay, i've been fairly busy lately.
So I actually have an update for this. We found the culprit. This project is the cause: https://github.com/kennethjiang/Teleport-NSLog
We can get the crash to occur repeatably now (every couple of minutes), by calling the following method repeatedly, while making writes to the database:
freopen(pathToNewFile, "a+", stderr);
This method is supposed to redirect stderr to a file.
For now we have just deleted the pod altogether. I shall see if I can find time to put together a minimal project that repeats the issue.
Thanks for the update! If you do put together a repro project we'd be interested in seeing it, but don't at all feel obligated to do so.
Goals
I wanted to open my realm.
Expected Results
I expected it to open.
Actual Results
It crashed.
Steps to Reproduce
The issue is not deterministic, and happens very infrequently (say after 1 hour of intense use, where we have dialed up the database activity to always read/write)
We use encryption, so these realms are all encrypted. We've managed to isolate it to one small piece of code:
Note that the mutex, realmMutex (which was added for debugging, is a global variable, so no thread can enter this simultaneously (even if there are multiple instances of the BIQDatabase class)).
If we comment out:
the issue disappears.
We have attempted to run compaction manually with the same result. (Using the old method (moving the database to a new place, then deleting the old one and removing the new one.) We have added code to ensure that this is only ever invoked the first time a database is opened.)
Basically we're stumped.
Code Sample
Realm framework version: 2.8.3 Xcode version: 8.3.2
iOS/OSX version: 10.3
Dependency manager + version: Cocoapods 1.12