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

HiveError: This should not happen. Please open an issue on GitHub. #624

Closed
tazik561 opened this issue Apr 7, 2021 · 10 comments
Closed

HiveError: This should not happen. Please open an issue on GitHub. #624

tazik561 opened this issue Apr 7, 2021 · 10 comments
Assignees
Labels
problem An unconfirmed bug.

Comments

@tazik561
Copy link

tazik561 commented Apr 7, 2021

In my application I used Hive .After release application , Some user faced with gray screen after a few days working with my application. I finally catch the error :

HiveError: This should not happen. Please open an issue on GitHub.

#0      BinaryReaderImpl.readFrame (package:hive/src/binary/binary_reader_impl.dart:249)
#1      FrameHelper.framesFromBytes (package:hive/src/binary/frame_helper.dart:17)
#2      FrameIoHelper.framesFromFile (package:hive/src/io/frame_io_helper.dart:41)
<asynchronous suspension>
#3      StorageBackendVm.initialize (package:hive/src/backend/vm/storage_backend_vm.dart:82)
<asynchronous suspension>
#4      HiveImpl._openBox (package:hive/src/hive_impl.dart:106)
<asynchronous suspension>
#5      HiveImpl.openBox (package:hive/src/hive_impl.dart:135)
<asynchronous suspension>
#6      DBModule._initBox (package:ip_flutter/div2/db_module.dart:80)
<asynchronous suspension>
#7      DBModule.initDb (package:ip_flutter/div2/db_module.dart:56)
<asynchronous suspension>
#8      _setLoginLessFlag (package:ip_flutter/ui/login/login_page_with_kyc.dart:1218)
<asynchronous suspension>
#9      _LoginPageWithKYCState.login.<anonymous closure> (package:ip_flutter/ui/login/login_page_with_kyc.dart:837)
<asynchronous suspension>

In the main method I initialized hive :

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  try {
    await di.init();
    await DBModule.initDb();
  } on Exception catch (e) {
    await _write("test.text", e.toString());
  }

This is my DBModule:

class DBModule {
  static bool isLoginLess = false;

  DBModule() {
    initDb();
  }

  static initDb() async {
    await Hive.initFlutter();
    if (!Hive.isAdapterRegistered(0))
      Hive.registerAdapter<ContactModel>(ContactModelAdapter());
    if (!Hive.isAdapterRegistered(1))
      Hive.registerAdapter<ContactDetailModel>(ContactDetailModelAdapter());
    if (!Hive.isAdapterRegistered(2))
      Hive.registerAdapter<CardBeans>(CardBeansAdapter());
    if (!Hive.isAdapterRegistered(3))
      Hive.registerAdapter<GetUserSourceCardResponse>(
          GetUserSourceCardResponseAdapter());
    if (!Hive.isAdapterRegistered(4))
      Hive.registerAdapter<GetPushNotificationContentListResponse>(
          MessageModelAdapter());
    if (!Hive.isAdapterRegistered(5))
      Hive.registerAdapter<CardOtpModel>(CardOtpModelAdapter());
    if (!Hive.isAdapterRegistered(10))
      Hive.registerAdapter<TransactionReceiptModel>(
          TransactionReceiptModelAdapter());

    if (isLoginLess) {
      print('DBModule.initDb LoginLess');
      await _initBox<ContactModel>(contactsBoxNameLoginLess);
      await _initBox<ContactDetailModel>(contactDetailsBoxNameLoginLess);
      await _initBox<GetUserSourceCardResponse>(sourceCardsBoxNameLoginLess);
      await _initBox<TransactionReceiptModel>(transactionsBoxNameLoginLess);
      await _initBox<CardBeans>(pCardsBoxNameLoginLess);
    } else {
      print('DBModule.initDb LoginFull');
      await _initBox<ContactModel>(contactsBoxName);
      await _initBox<ContactDetailModel>(contactDetailsBoxName);
      await _initBox<GetUserSourceCardResponse>(sourceCardsBoxName);
      await _initBox<TransactionReceiptModel>(transactionsBoxName);
      await _initBox<CardBeans>(pCardsBoxName);
    }
    await _initBox<GetPushNotificationContentListResponse>(pushMessageBoxName);
    await _initBox<CardOtpModel>(cardOtpBoxName);

  }

  static Future<void> _initBox<T>(String boxName) async {
    if (!Hive.isBoxOpen(boxName)) await Hive.openBox<T>(boxName);
  }
}

In login page I called again

  DBModule.isLoginLess = loginLess;
  await DBModule.initDb();

to add some box according some user condition .

The application is working but why after a few days , Application is started with gray page and this error?

@tazik561 tazik561 added the problem An unconfirmed bug. label Apr 7, 2021
@sezaru
Copy link

sezaru commented May 4, 2021

I got this exact same error, I use hive when starting my app and when receiving a new notification.

Here is the error when starting the app:

2021-05-04 10:29:00.182 337-380/agj.alarm_app E/flutter: [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: HiveError: This should not happen. Please open an issue on GitHub.
    #0      BinaryReaderImpl.readFrame (package:hive/src/binary/binary_reader_impl.dart:250:7)
    #1      FrameHelper.framesFromBytes (package:hive/src/binary/frame_helper.dart:21:26)
    #2      FrameIoHelper.framesFromFile (package:hive/src/io/frame_io_helper.dart:42:12)
    <asynchronous suspension>
    #3      StorageBackendVm.initialize (package:hive/src/backend/vm/storage_backend_vm.dart:86:11)
    <asynchronous suspension>
    #4      HiveImpl._openBox (package:hive/src/hive_impl.dart:116:9)
    <asynchronous suspension>
    #5      HiveImpl.openBox (package:hive/src/hive_impl.dart:145:12)
    <asynchronous suspension>
    #6      NotificationQueue.openBox (package:alarm_app/utils/notification_queue.dart:10:58)
    <asynchronous suspension>
    #7      SplashInitializer._initHive (package:alarm_app/service/splash_initializer.dart:36:5)
    <asynchronous suspension>
    #8      SplashInitializer.initialize (package:alarm_app/service/splash_initializer.dart:20:5)
    <asynchronous suspension>

And here is the error when starting from new notifications:

2021-05-04 10:25:01.928 25270-25757/agj.alarm_app I/flutter: Notification exception: HiveError: This should not happen. Please open an issue on GitHub.
2021-05-04 10:25:01.948 25270-25757/agj.alarm_app I/flutter: package:hive/src/binary/binary_reader_impl.dart 250:7           BinaryReaderImpl.readFrame
    package:hive/src/binary/frame_helper.dart 21:26                 FrameHelper.framesFromBytes
    package:hive/src/io/frame_io_helper.dart 42:12                  FrameIoHelper.framesFromFile
    dart:async                                                      _Completer.completeError
    package:hive/src/hive_impl.dart 122:19                          HiveImpl._openBox
    dart:async                                                      _asyncErrorWrapperHelper
    package:hive/src/hive_impl.dart 145:18                          HiveImpl.openBox
    package:alarm_app/utils/notification_queue.dart 10:69           NotificationQueue.openBox
    package:alarm_app/service/push_notification_service.dart 93:31  PushNotificationService._processBackgroundMessage.<fn>
    dart:async                                                      _asyncThenWrapperHelper
    package:alarm_app/service/push_notification_service.dart        PushNotificationService._processBackgroundMessage.<fn>

Any update on this? Seems like a very critical bug since it basically turns the DB unusable.

@tazik561
Copy link
Author

tazik561 commented May 4, 2021

I found out , If you dispose page when hive storing data into box , The box is corrupted and this cause I got white screen.

@sezaru
Copy link

sezaru commented May 4, 2021

Hey @tazik561 thanks for the update, just to be sure I got it right, when you say dispose page, you mean closing a box? Or you mean removing some data from the DB or something else?

@tazik561
Copy link
Author

tazik561 commented May 4, 2021

Hey @tazik561 thanks for the update, just to be sure I got it right, when you say dispose page, you mean closing a box? Or you mean removing some data from the DB or something else?

Look, I save into db in initstate. Imagine I have 2 page A and B . In B initstate method I save data in hive.When I transmit from A to B, immediately I press back button to return into page A. Means I don't let to hive to persist data completely and I think data is corrupted.

@sezaru
Copy link

sezaru commented May 4, 2021

I'm trying to reproduce this in a consistent way but without success..

I will upload here the .hive file from my broken DB to see if this can help the devs find out the issue:
notification_queue.zip

I love this library, but for now, I will try to find an alternative, I cannot afford to have randomly a broken DB and lose all the data in it.

@EternalYouth29
Copy link

I'm facing this error along with couple of other issues when integrating FCM with Hive.

I tried to save message.data into Hive in _firebaseMessagingBackgroundHandler(), when the app is in the background, the code run successfully but failed to retrieve the latest data with the same key once I back into the app. The latest data only appears after I restart the app.

And after played around with the notification this error occurred and Hive stop working, I have to re-install the app.

@sezaru , have you found any alternative db like Hive to use? Any recommendation ?

@sezaru
Copy link

sezaru commented Jun 14, 2021

@EternalYouth29 Indeed I have, I'm using https://pub.dev/packages/objectbox as an alternative, didn't have any problem with it so far.

@EternalYouth29
Copy link

@sezaru thanks a lot for the info.

@tazik561
Copy link
Author

@EternalYouth29 Indeed I have, I'm using https://pub.dev/packages/objectbox as an alternative, didn't have any problem with it so far.

does it support web ?

@themisir
Copy link
Contributor

Closed with #914.

Please upgrade to hive v2.0.6.

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

No branches or pull requests

5 participants