Skip to content
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

MdbxError(11) #60

Open
2 of 3 tasks
FritzMatthaeus opened this issue Apr 24, 2024 · 6 comments
Open
2 of 3 tasks

MdbxError(11) #60

FritzMatthaeus opened this issue Apr 24, 2024 · 6 comments

Comments

@FritzMatthaeus
Copy link

Steps to Reproduce

The Database is failing with an MdbxError(11) as shown in the logs. This bug is hard to reproduce. Personally, i have not encountered it in production yet, others have. Sometimes it occurs after hot reloading the app several times. It seems to be an Error in the Rust part of Isar and i have no clue how to look into that myself. Maybe you can.

There is an ongoing issue at the original Isar repository:

isar#1068 (comment)

Here are my logs:

E/flutter (29750): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: IsarError: Cannot open Environment: MdbxError (11): Try again

Code sample

Take the counter app, add whatever IsarSchema and open it on running the App. Then hot reload the App a couple of times. I cannot guarantee, that this will produce the Error.

void() main async {
WidgetsFlutterBinding.ensureInitialized();
final dir = await getApplicationDocumentsDirectory();
await Isar.open([schemas], directory: dir.path);
runApp(MyApp());
}

Details

  • Device: Samsung A53
  • Platform: Android 12.
  • Flutter version: 3.16.8
  • Isar version: 3.1.6

  • I searched for similar issues already
  • I filled the details section with the exact device model and version
  • I am able to provide a reproducible example
@tomekit
Copy link

tomekit commented May 22, 2024

I am not sure if it helps you to reproduce this issue, but in our case we're getting this error consistently once user uses a back arrow (instead of hamburger menu icon) on Android to close the app (goes to detached state) and then taps the app again so it starts again: isar#1068 (comment)

@linbiaojj
Copy link

I wrote a demo to reproduce this issue on an Android phone. When the app returns to the home screen while a database write operation is in progress but not yet completed, and then the app is reopened, this issue occurs.

https://github.com/linbiaojj/isar_mdbx_error_demo

@Tr736
Copy link

Tr736 commented Jul 29, 2024

I discovered that adding a delay on launch before writing or reading to give the database time to open fully resolved the issue for me. Must be a data race from within the package

@vizakenjack
Copy link

vizakenjack commented Aug 28, 2024

Looks like I found a workaround too.

The task is to prevent the app from going to the detached state after pressing 'back.'

Add this to your Home widget:

PopScope(
   canPop: false,
   onPopInvokedWithResult: (bool didPop, Object? result) {
      if (isIos || didPop) return;

      _closeConfirmation();
   },
 child ...

I use a modal popup with the message 'Do you really want to close the app?' If the user presses 'close,' I call exit(0). Please note that SystemNavigator.pop() will have the same effect as 'back' button, so you need to use exit(0).

In this variant, the app never goes to detached state and there won't be any issues with MdbxError(11).

However, there still could be issues with existing transactions, and you can add a function to await them before exiting

UPD: it's better to use https://pub.dev/packages/flutter_exit_app instead of exit(0)

@marcotta
Copy link

@Tr736 can I ask you if you added the delay before opening the database or before the first write/read operation.
Out of curiosity what delay duration worked for you?

In my case I added a delay before the first opening of the DB of 300 ms and I am still seeing the error reported in Crashlytics.

@Tr736
Copy link

Tr736 commented Sep 12, 2024

I’ve added the delay after opening and before the first write

unfortunately this repo is pretty much dead and with the new flutter versions I’ve noticed a massive spike in cpu and memory allocations along with all the other issues we’ve experienced.

we’ve decided to pull the database from our repo, which is a lot of work :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants