-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Ensure inputs are closed on error. Add runtime GC finalizer as additional guard to close iterators #8716
Conversation
* <type>FinalizerIterator sets a runtime finalizer and calls Close when garbage collected. This will ensure any associated cursors are closed and the associated TSM files released * `query.Iterators#Merge` call could return an error and the inputs would not be closed, causing a cursor leak
0ab9920
to
4233763
Compare
updated commits with debug code removed |
@stuartcarnie I haven't used What's the goal? |
@benbjohnson the primary goal is to address any consumers of I have read that post before. It was started by Dmitry because the Go GC was not a precise garbage collector, thus you could not rely on GC finalizers being called. That has since been rectified with 1.3. Rob Pike responded that it wasn't as gloomy as Dmitry made it out to be and later Rob clarified they were not going to be removed. They are used for a similar purpose in the |
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 should make a concerted effort in the future to put the work in to weed out where calls to Close
are getting missed, rather than relying on this approach.
My only nit with this PR is the naming for the iterators. They're still merge iterators, so I think they should be called XMergeIterator
, whether X
is Guard
or something else.
Same thing for, for example, FloatFinalizerIterator
. It's a type of FloatIterator
, so it seems to me that it should be called, for example, FinalizedFloatIterator
or something.
Agreed @e-dard, the long term goal would be to make sure The other struct names for the iterators in the Q: Do you think we should change that?
I'll rename the |
@stuartcarnie I think the changes are good. 🍏 |
newMergeGuardIterator
ensuresinputs
are closed ifMerge
returns error and wraps the returned merge iterator in<type>FinalizerIterator
Close
when garbage collected. This will ensure any associated cursors
are closed and ref counts on related TSM files released
query.Iterators#Merge
call could return an error and the inputswould not be closed, causing a cursor leak, hence the
newMergeGuardIterator
Required for all non-trivial PRs