-
Notifications
You must be signed in to change notification settings - Fork 223
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
Close iterators #1542
Close iterators #1542
Conversation
Codecov Report
@@ Coverage Diff @@
## v0.9.0-dev #1542 +/- ##
==============================================
- Coverage 61.65% 61.56% -0.10%
==============================================
Files 512 512
Lines 19499 19644 +145
==============================================
+ Hits 12023 12093 +70
- Misses 5757 5795 +38
- Partials 1719 1756 +37
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we want to make sure nobody uses iterators after Close, at the very least for the sanity of the thing, and later down the road to maybe release some resources.
Even just setting iterator.isClosed = true, and then erroring out on any function that returns an error can be a good start.
So do we want to add an |
I believe we do.
Yeah, I thought about that and didn't really come up with a solution I'm 100% satisfied with. |
If the |
Yeah, I though about this, it indeed will achieve the desired behavior, at the price of correctness (Next returning true while there's no actual Next). |
We use goleveldb for our database, and it explictly says that all iterators must be released:
https://pkg.go.dev/github.com/syndtr/goleveldb/leveldb#Transaction.NewIterator
I'm not sure if in practice this means we're leaking memory, because goleveldb uses
runtime.SetFinalizer
to call the Release, but we don't want to trust it works correctly, and also goleveldb never promised it's doing that, so they can always stop doing that.I did not explictly invalidated the iterators, so some iterators could still be "used" after closing, and closing won't free their memory (assigning nil to all fields), but I'm open to discuss that with or without an explicit
isClosed
flag in all iterators.