-
-
Notifications
You must be signed in to change notification settings - Fork 177
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
Fix segfaults on close and gc #597
Conversation
@ralphtheninja this is what a draft PR looks like :) |
Node 10 on Linux failed:
I'll see if I can replicate it. |
If I repeat the |
Aaah now I see what draft means. Nice feature. |
This still occasionally fails. The current solution is an open invitation to race issues. @ralphtheninja Instead, could we somehow prevent GC of |
Note to self (I'll pick this up again end of week): |
@@ -506,6 +520,7 @@ struct Iterator { | |||
if (gte_ != NULL) { | |||
delete gte_; | |||
} | |||
delete options_; |
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.
Without this, node --expose-gc test/leak-tester-iterators
shows endlessly growing memory, also on master.
The last commit (f8d97b9) is probably too much for this PR (because it is not related to iterators, but fixes #157) - it was something I wanted to explore. I'll revert it later (as well as squash the other commits). Edit: actually I quite like it, so I'm leaving it for review. In follow-up PRs we can then easily apply the fix to other operations, by swapping |
f8d97b9
to
47fc4db
Compare
47fc4db
to
195c78c
Compare
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.
Nice work @vweevers !
I've just ran into the exact same issue last week, although I'm still getting used to NAPI, I can confirm it is fixed right now, so LGTM.
@vweevers @ralphtheninja -- one thought I've had for maybe the past couple years now is that we could "auto end" iterators on GC. This probably belongs in a separate issue, but it would allow for nice clean code with a promise wrapper. e.g. for await (const [key, value] of db.iterator(options))
console.log([key, value]); As opposed to: const iter = db.iterator(options);
try {
for await (const [key, value] of iter)
console.log([key, value]);
} finally {
await iter.end();
} The former is currently impossible to do since the body of the loop may throw an error, which the async iterator cannot account for. What do you guys think? |
It's a good idea. |
I don't think the lack of syntactic sugar is a decisive argument. Note there is an ECMAScript proposal for explicit resource management. That said, I don't have a good argument for preserving If we can make it happen, great! |
While this part of |
I think I have a viable, lock-free strategy:
|
Closes #589, closes #157.