New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
io.realm.exceptions.RealmFileException when launching application #4524
Comments
Bad file header can be caused by compacting in multiple processes. |
@Zhuinden : I do not use compact method, so why do it happen? |
@jollyjoker992 Does your app have multiple processes? Does it happen the first time your app is launched? Did the device run out of disk space? |
@kneth : No, my app is single process. It does not happen in the first time launching app, It happens in many time when launching app. I have attached code above and it is located in Application class. From Fabric report, all devices has enough free disk space. |
@jollyjoker992 Is there a pattern in which devices you see the crashes? How easy is it to reproduce (i.e., how often does it happen)? |
@kneth : Because I get crash report from users by Fabric, so I cannot reproduce it. So, sometime It happens when I launch app, I trace log and see all of issues I mentioned above. From Fabric, it happens in:
Can you tell me all of reasons make all of above issue? I will try to verify each reason and hope find out the root cause. Thank you. |
@jollyjoker992 So no obvious patterns 😢 If you can post the stack trace/log from one or two of the crashes, it might be useful. |
@kneth : Below is one of crash logs I just found right now. I will update more log later. Thank you.
|
A possible fix for I think this error is being investigated in #4559 |
@jollyjoker992 With #4559 merged, you can try a snapshot release and see if it solves your issue. |
@jollyjoker992 No exact date but we will probably do a release in a week or two (we don't have fixed date as support load or critical bugs are hard to predict). |
@kneth : I tried to use Snap shot for testing this issue. So, Can you close this issue? I will re-open it or note for you after a few days for testing. Thank you for your support. |
@kneth : Hi. I have tried to use Realm Snap-shot 3.2.0 to test the latest version (the last version is 3.0.0). The issue 'Bad realm file header' maybe resolved, I have not seen it in crash report. But, the below issues still occurs.
I close Realm instance follow App life cycle, but when system kills my app (on low memory case), I cannot close it. So, Is it a root cause? Pls help me to investigate problem by showing me some cases that these issues may occur. Thank you so much. |
This is generally caused if the Realm file is too large, which is generally when there is at least one unclosed Realm instance on a non-looper background thread. |
If your Realm file is corrupted, it shouldn't be possible to open it on any thread? |
@cmelchior : I think there are some cases meets my above question. For example, when I open more than 2 async transaction at the same time, we have more than 2 Realm instance in back ground thread but one of them throws the corrupted exception, another instance is in non-finished transaction and when I catch this exception, I delete the realm file immediately but I cannot because there are a realm instance has not been closed :( |
@cmelchior @Zhuinden @kneth Thanks for your support. I'm currently catching the Exception when openning Realm instance then delete it if need and recover Realm file by supporting from server side.
If open many transactions at the same time causes Realm file size becomes too large, so It seems like a bug, right? Can you control it to reduce the Realm file size like compact method is defined ? |
@jollyjoker992 have you tried with Realm 4.2.0? It should have a bunch of multi-process related fixes (because of Realm Core 4.0.3). |
@Zhuinden : No, I have not yet but I will try it 👍 Thanks you |
@Zhuinden : Realm 4.2 release note is not mentioned about the issue below? It is fixed ?
|
@jollyjoker992 I mean that says your Realm file grew to Is that normal for your amount of data? |
@Zhuinden , @cmelchior |
@huunam118 you mean you do |
@Zhuinden |
@Zhuinden @cmelchior I have a question relate this issue, pls help me. Can I copy all data from old Realm file (corrupted with a large file size) to a new Realm file (create new file) without query and insert ? Of course, I want to keep both of them and switch to the expected file when working with them and just copy data (I don't want to clone a file with a large size). Thank you |
If it still can be opened and you just want to reduce the Realm file size, use But it is still important why the file grows too big, normally it is just because of Realm instances are not closed on the background thread. |
@beeender : I think because I opened too many transaction at the same time so the Realm file grow up with the large size.
cannot help me :( Reference: #4524 (comment) |
So it is because of you really write that much of data to the Realm? One thing you can do is query for the data you don't need and delete them by |
@beeender : No, I did not write too much data because the data is very simple. Reference to here, I think it's the root cause make my Realm file grow up with a large size. But I'm currently focusing on the issue that : How can I copy all realm data from the old file (with the large size but has not corrupted) into a new file without query and insert. |
If that is the case, Can the large Realm file still can be opened? |
@beeender : I tried it but It cannot help me until the Realm file being corrupted. |
If "Realm file being corrupted." means that it fails to open the file by |
@beeender : Thanks for your supporting. I tried to use the compact() method when launching the application but It seems cannot help me anything until the file being corrupted. So, when the compact() method should be called to compact Realm file? When launching app or when close app? And If the file grows up because of here, the compact() method can help me? |
compact operation may take some time to finish depends on how much valid data stared. https://realm.io/docs/java/4.3.1/api/io/realm/RealmConfiguration.Builder.html#compactOnLaunch-- |
@beeender : Should I compact when closing app? Ex: compact() then close Realm instance (I just use only 1 instance of Realm in my app) |
|
@beeender Thanks for your support. I will try it and feedback about the result for you ASAP. Many thanks from my heart 🙇♂️ |
@beeender Sorry because mention you but I need help from you. To detect and recover data after Realm file is corrupted, I need to make a Realm file that is corrupted for testing. So pls help me to know how to corrupt a Realm file manually? Thank you. |
@jollyjoker992 You can just provide any file that's not a realm file. An empty one for instance. |
@bmunkholm I need a Realm crash when call |
@Zhuinden @kneth @cmelchior @beeender |
Only |
@cmelchior Thanks. Sorry because I mentioned you many times. I am currently try to find the root cause of corrupted Realm file in my app. Thank you again. |
I have researched many and many times about this issue but I have not found any solution.
I am implementing an Android application with Realm Android 3.0 and using Fabric to find out crash report.
Below is Realm initialize code in Application class:
I get many crash report from Fabric related with
io.realm.exceptions.RealmFileException
such as:So, can you tell me the reason of this issue? Thank you.
The text was updated successfully, but these errors were encountered: