objectbox-java icon indicating copy to clipboard operation
objectbox-java copied to clipboard

io.objectbox.exception.DbException Not a database file (-30793)

Open hzhyan opened this issue 4 years ago • 13 comments

Describe the bug io.objectbox.exception.DbException Not a database file (-30793)

Basic info (please complete the following information):

  • ObjectBox version : [2.8.1]
  • Reproducibility: [occasionally without visible pattern]
  • Device: [series]
  • OS: [series]

Expected behavior A clear and concise description of what you expected to happen.

Code boxStore = MyObjectBox.builder().androidContext(context.applicationContext).build()

Logs, stack traces

io.objectbox.exception.DbException: Not a database file (-30793)
--
java.lang.RuntimeException:Unable to create application com.qq.ac.android.ComicApplication: io.objectbox.exception.DbException: Not a database file (-30793) (error code -30793)
android.app.ActivityThread.handleBindApplication(ActivityThread.java:5770)
......
Caused by:
io.objectbox.exception.DbException:Not a database file (-30793)
io.objectbox.BoxStore.nativeCreateWithFlatOptions(Native Method)
io.objectbox.BoxStore.<init>(SourceFile:17)
f.b.d.b(SourceFile:5)

Additional context Initialization of the database is in the main thread, the main process. It was initialized only once.

hzhyan avatar Jan 25 '21 03:01 hzhyan

Does your code supply the database file? Does it somehow (delete and) create the database file? Note that on Android ObjectBox stores the database file in the app's files folder.

greenrobot-team avatar Jan 25 '21 09:01 greenrobot-team

Does your code supply the database file? Does it somehow (delete and) create the database file? Note that on Android ObjectBox stores the database file in the app's files folder.

I used ObjectBox in my app witch has ten millions of users, thousands of users crashed, but count millions of crashes, this means the users crashed always keep crashing. i just init ObjectBox in Application’ onCreate().

I saw this crash on a crash analysis platform like Fabric. It is difficult to determine the user's actual environment.

What happens if the database file is corrupted? Is it going to crash?

hzhyan avatar Jan 25 '21 11:01 hzhyan

Well, as a quick fix, you could catch that exception and delete the offending data file and start over with a clean slate.

Alternatively, we could think about how a user may provide the data file to you/us to investigate this further.

greenrobot avatar Jan 25 '21 13:01 greenrobot

In order to repeat this crash, I edit the data.mdb file on my device, it crashed. But the crash log is different.

io.objectbox.exception.DbException: Could not open database environment; please check options and file system (13) (error code 13)

I got this log.

To fix the crash, first i need to repeat it. Do you know how to repeat the crash on my device?

hzhyan avatar Jan 26 '21 01:01 hzhyan

What @greenrobot meant was that the database is likely corrupted. Try to write code that catches the exception, then deletes the broken file. Then try to create a new BoxStore. E.g. like:

try {
    boxStore = MyObjectBox.builder().androidContext(context.applicationContext).build()
} catch (e: DbException) {
    BoxStore.deleteAllFiles(context.applicationContext)
    // Try to create a new empty store.
    boxStore = MyObjectBox.builder().androidContext(context.applicationContext).build()
}

If possible, you might add an error dialog and ask users to send the corrupted database file (then send it to us for analysis).

greenrobot-team avatar Jan 26 '21 14:01 greenrobot-team

If possible, you might add an error dialog and ask users to send the corrupted database file (then send it to us for analysis).

this is a good idea. So, you don't know how the file gets corrupted when you throw this exception?

As I said before, I placed one wrong file in the corresponding folder and got another crash log.

hzhyan avatar Jan 27 '21 01:01 hzhyan

So, you don't know how the file gets corrupted when you throw this exception?

There are some consistency checks in place when opening a data file. If it finds data in the file that is not plausible it will trigger an error. So, no we do not know how this happened. You are the first one to report this. Other apps with millions of users do not have that issue.

I placed one wrong file in the corresponding folder and got another crash log.

It's unlikely that you hit exactly the same bytes that caused the -30793 error code.

greenrobot avatar Jan 27 '21 19:01 greenrobot

Got it. I will try to get the corrupted database file, then send it to you. It will take some time.

hzhyan avatar Jan 29 '21 03:01 hzhyan

Without additional information, we are unfortunately not sure how to resolve this issue. Therefore this issue has been automatically closed. Feel free to comment with additional details and we can re-open this issue.

no-response[bot] avatar Feb 22 '21 08:02 no-response[bot]

@hzhyan If you have none already, we have published example code on how to safely get a copy of the database file and offer users to share it via email. Note this uses a new API BoxStore.isDatabaseOpen introduced in version 2.9.0. https://github.com/objectbox/objectbox-examples/commit/d8658ec8867541db4b5516534abbd2c350eec339

greenrobot-team avatar Feb 22 '21 10:02 greenrobot-team

data.mdb.gz About this question, I finally got the error database file. @greenrobot-team @greenrobot

hzhyan avatar Jun 10 '21 07:06 hzhyan