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
Do not return uninitialized box #916
Do not return uninitialized box #916
Conversation
In nutshell if some one calls |
Yes that's correct. But there's another issue with your proposed solution. Check #846 for additional details. TLDR if initialization fails db file keeps locked on WindowsOS, so you can't delete or re-open said box. |
Also when you re-call openBox it will not return uninitialized box because we have some sort of locking mechanism in place that will await openBox calls to same box while initialization completes. |
It looks like This is not to say our implementation is flawless. Ofc it's still buggy as someone can call Maybe we can try fixing #846 in a different way instead. One way I can think of is closing box on initialization failure.. Let me know what you think about that. /cc @Jon-Salmon, I would like to know your thoughts too PS: sorry for comment spamming |
It is possible to return uninitialized box since Run my example code and check output. And you can see that the first breakpoint returns the box while initializing it. |
True! Missed that part, sorry. Let's merge your patch and I'll work on fixing #846. |
I think this can be moved before In catch block it can be closed if it's not I think these should be nullable So close close should only close underlying file if it is not This is because open can fail too and we can avoid |
#846 fix should be rerolled.
_boxes
can contain a box which isn't initialized so it is possible thatisBoxOpen(name)
returntrue
and program can acquire this uninitialized box which can lead serios problems for examplebox.put
called.Imagine the following situation:
In this case
sameBox
can be referenced before it's initialized. However this cannot be achieved so easily because we have to get the reference after_boxes[name] = newBox;
and duringawait newBox.initialize();
call (and also after_manager.open
).There is a period when both
isBoxOpen(name)
and_openingBoxes.containsKey(name)
returntrue
.Let me a show an example (I won’t be bored with how the dart event loop works, this is the easiest example):
There is another fix just place
_openingBoxes.containsKey(name)
check before_boxes[name] = newBox;
however I think there shouldn't be any point in time when both returntrue
, moreover in case of error_boxes
will contain an unitialized box.#846 should use
Hive.deleteBoxFromDisk('boxName');
which handles the delete of unopened box ( see implementation ).