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
Unhandled Exception: HiveError: This is an internal error. #94
Comments
This seems to happen very rarely or only under certain conditions. Unfortunately I cannot do much if I'm unable to reproduce it. All the integration tests work fine... It would be really helpful if you or someone else finds a way to reproduce this bug. I'll also try to find it. Until then you should switch to the latest stable version ( |
Is #71 resolved in |
Yes it is. But I don't think this issue is related. |
Just to know when looking for a way to reproduce it, is it that the data is corrupted somehow and it cannot be read when the box is opened? or is it something else having to do with the box itself? |
Exactly. There are two things that can cause this:
|
Well im not using type adapters. Ill take a look and double check what im actually writing to boxes. Perhaps im writing something in such a way or some sort of type that is causing it. Thanks for the insight. |
If you write an usupported type, it should fail immediately without actually persisting anything. Thanks for trying to reproduce the issue... |
I also encountered this on
|
@dat7e Do you run Hive integration tests or your own? Would you be willing to share a test which fails for you? |
Sorry I haven't been clearer. I ran my own integration tests (e2e to be more exact) which I wrote for my app. The tests are very simple ones that fill out and submit a login form. When valid credentials are given, the user is redirected to a news feed which fetches data via http and caches the news items using Hive This is how I open the boxes:
|
Would it be possible to share some code that reproduces the problem? I have a hard time to reproduce the issue myself... |
Currently no, sorry. It's under NDA and all that jazz. However the feature I tested is small and I might be able to extract it to a small project, hopefully in a few days. Will also try to find out how to consistently reproduce the issue. Right now it looks to me a lot like #71, could these two be related in any way? |
Yes I think they have the same root cause. Please upgrade to Thank you very much for your help :) |
I have the same error at 1.1.1 after crash at debugging. I don't know how to reproduce it. |
my colleague encountered this on iOS simulator today, hive version 1.1.1 |
I'm opening boxes on startup, One box specifically keeps failing. Im just throwing stuff out here but in my case it's the "state" box which is written to very frequently. Could it be possible that data isnt being written correctly, or is being written quickly (asyncs) that is causing the box to become corrupted? I have a few other boxes loaded before the state box on startup and they never have issues. |
I still have no idea what might cause this problem :/ All the unit tests write a huge amount of entries very quickly and they never corrupted a box. |
Ill be working on something hotloading etc for about 30 minutes, then at some point, as usual something wont hotload, so i restart the app and it fails to launch (black screen) with the same error. I have no way to reproduce this and i've never seen it happen outside of hotloading / development, but Im pretty much forced to make a wrapped storage interface in the event that this problem does happen on production. Clearly something is being written or in a specific way that is corrupting it, but that is not enough information for a fix. I cannot reproduce it 100% it just happens randomly during development. |
I have a really hard time finding this bug and no idea where to start. |
That could be possible. With the very little testing i've actually done with production & whatnot i cant be sure. I have made a temporary bandaid fix for now to basically wipe the hive file that gets corrupted and create a new box (the only box failing is the one i use for network caches, so re-creating it isnt so bad) I will be doing some legit tests pretty soon with others, I'll let you know if anything comes up. But I agree, I think it has something to do with hotloading, I have only seen it after restarting the application (after rapid hotloading doesnt update the app). |
Thanks for your help! |
I have a similar problem when I develop on windows for Android. When I write on Mac OS for iOS there is no problem |
You mean in an emulator or with Flutter desktop? |
android \ ios emulators |
Okay, thanks! If find a way to reproduce it, I would be grateful for a hint or demo... |
I had one of these in my sentry logs today (using hive 1.1.1). I cleared the box file with clearing the app data, and it worked again. I am using 3 generated type adapters, but nothing fancy. If I can get this reproduced in a simple way I'll make sure to post it here. These are the harder nuts to crack.
All relevant box operations: Future<SavedGame> getSavedGame(String uri) async {
var gameBox = await Hive.openBox("games", lazy: true) as LazyBox;
var savedGame = await gameBox.get(uri);
if (savedGame != null) {
return savedGame as SavedGame;
}else {
return null;
}
}
Future<void> saveGame(LocalGame game, BoardState currentBoardState) async {
var gameBox = await Hive.openBox("games", lazy: true) as LazyBox;
var savedGame = SavedGame.from(game, currentBoardState);
await gameBox.put(game.uri, savedGame);
return;
}
Future<void> deleteAllSaveGames() async {
var gameBox = await Hive.openBox("games", lazy: true) as LazyBox;
await gameBox.clear();
return;
} |
@markmooibroek Thanks! |
Still having issues. I believe when you are using the same box across multiple screens, it causes issues. Is it ok to use the Same box with watchedbox in two different screens? |
Even when you disable compaction and clear the cache?
Absolutely. |
Yes...even after disable compaction, i am getting this issue. It is proprietary code :-(. I can do a screenshare with you. Any email ids? |
Is it possible to detect exception , recreate the box and open it again. |
I have modified my code to detect exception and delete the box file (say my_box.hive) and lock file (my_box.lock) and trying to open the box fresh. I will keep you posted about how it handles. @leisim Do you think if this is the right approach? |
@leisim Any luck? I am stuck. my app build around hiveDB. :-( |
Could it be, that Hive gets initialized before you call Edit: Edit 2: So Hive should check against null as path. If you use Flutter you should call |
@ueman I am initializing the Hive on Main and Opening 5 Boxes in the process. Out of 5, only one is always failing. all others are working as expected. |
Hi, I got the same issue :( on my IOS simulator. It's weird, it was working before. Could it be a file corruption? Alain |
Good news. I found the problem and I'm working on a fix. The problem is that compaction doesn't happen when it is supposed to. If disabling compaction (the workaround above) does not work for you, please open another issue. @alaindixon This sounds more like a problem with the added fields. Did you follow the guide on adding fields in the docs? |
Hi, I'm having the same problem and I've created a minimal sample to reproduce it reliably (at least on Android and iOS). The following steps will throw an Exception on the latest version of the master branch (5605d1c):
Step 4 will throw the exception. It's working fine if you don't compact the box or don't delete any entry. I've tried to find the root-cause, but I could not find the exact line of code. It is definitely related to the Here is a minimal Flutter app for reproduction. I'm on the latest flutter master branch.
|
@OliverWelther I don't know how to thank you. I really works and I'll look for the problem right now. |
Thanks to @OliverWelther I finally found the problem. I used Edit: I will publish a test version of |
@leisim is there a branch containing the fix anywhere? Running into the same issue here. |
@MichealReed Are you using version |
I did not notice the dev packages. Thank you! |
Update: I can confirm that the issue persists on |
@michaelreed, please use |
Upgraded to v1.2.0, thanks. |
@leisim I encountered this again today and have had reports from others of the same happening. Only way to remedy is to delete the app's data. |
@MichealReed you're the only one I know of who still has this problem :/ (the others just forgot to update to the latest version). It's very hard to diagnose this issue without additional information / code. |
We are both definitely on 1.2.0. It is much less frequent, but still happens. Not sure what code to provide as I'm not sure what exactly triggers it, but I have only seen this on Android so far. I would suspect that the majority of people using hive have not upgraded and this issue will mainly surface on new implementations/projects. |
I had similar problems when trying to start Hive twice or when trying to open an already opened box. My solution was to create a singleton that guarantees the handling of that. I think it would be interesting to have that at the library level |
How do you use BufferedFileWriter ? I am using TypeAdapter to read and write and Now I got white screen after a while users works with my application and the application couldn't lunch again .Just shows white screen |
Steps to Reproduce
No good way to reproduce, ends up just leaving the app in a dead-start state since a box cannot be opened. All i'm running is openBox on startup (which normally causes no problems)
Version
v1.10.15-pre.151
1.1.0-beta2
Note that the same issue happens when downgrading back to flutter stable
Finally, During this installation, I did not clear data (using box.clear) so i dont think it's related to #71
The text was updated successfully, but these errors were encountered: