Skip to content
This repository has been archived by the owner on Aug 31, 2018. It is now read-only.

src: clean up handles (preparation for workers) #85

Closed
wants to merge 5 commits into from

Conversation

addaleax
Copy link
Contributor

Also split out from #58

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

src

Previously, handles would not be closed when the current `Environment`
stopped, which is acceptable in a single-`Environment`-per-process
situation, but would otherwise create memory and file descriptor
leaks.
This allows easier tracking of whether there are active `ReqWrap`s.
@addaleax addaleax requested a review from a team September 27, 2017 20:43
fn,
env()->event_loop(),
req(),
MakeLibuvRequestCallback<T, Args>::For(this, args)...);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm misreading, but doesn't MakeLibuvRequestCallback<...>::For(...) make the callback variadic, not the call? For is just returning a single T function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sooo … I am not sure I’m getting the question right 😄 What this does is write MakeLibuvRequestCallback<T, Args>::For(this, ?) for every arg ? in args.

http://en.cppreference.com/w/cpp/language/parameter_pack#Pack_expansion can explain this better than I can :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhh...I get it now. Thanks for the clarification.

Perhaps all that template wizardry could use some more elaborate comments? I suspect a lot of people less familiar with C++ templates will look at that stuff and have no idea what is going on. 🙀

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of core could use more comments tbh.

Unfortunately, the template wizardry isn't just ours alone - we simply won't ever fully get away from V8's liberal use of them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a history of poorly documented code doesn't mean we should keep poorly documenting code.

Also, I don't think the V8 comparison quite fits here. The consuming side of the API is fine, it's what is going on behind the scenes that is confusing. Unlike V8, we have to maintain this code entirely ourselves, so it's important we make it understandable to anyone whom may need to work on it in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I’ve added a comment here that should help a bit – @Qard maybe take a look whether this is clear enough :)

One problem here is that this is very subjective – from my perspective what V8 does seems like nothing :) So yes, I really appreciate these comments.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that should be fine. I just want us to get in the habit of making the design of things in core clearer as that will make it a lot more accessible to potential new contributors. There are many people whom could make meaningful contributions to the native code, but don't have a lot of native dev experience or perhaps just haven't worked with C++-specific things like templating. 😸

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree 100 % :) It might be nice to write something along the lines of a tutorial for contributing to the native side of things … even people who are used to writing C++ have a bit of a hard time adjusting to the way the V8 API works

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I started working on some Node.js internals docs a few years ago, which I believe are still in the website repo somewhere. I don't think they are exposed in navigation though and could probably be updated and expanded.

Workers cannot shut down while requests are open, so keep a counter
that is increased whenever libuv requests are made and decreased
whenever their callback is called.
@addaleax addaleax force-pushed the workers-handlecleanup branch from 9b80626 to a42c922 Compare September 28, 2017 17:23
@addaleax
Copy link
Contributor Author

MacOS CI should be good now :)

addaleax added a commit that referenced this pull request Sep 30, 2017
Previously, handles would not be closed when the current `Environment`
stopped, which is acceptable in a single-`Environment`-per-process
situation, but would otherwise create memory and file descriptor
leaks.

PR-URL: #85
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
addaleax added a commit that referenced this pull request Sep 30, 2017
This allows easier tracking of whether there are active `ReqWrap`s.

PR-URL: #85
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
addaleax added a commit that referenced this pull request Sep 30, 2017
Workers cannot shut down while requests are open, so keep a counter
that is increased whenever libuv requests are made and decreased
whenever their callback is called.

PR-URL: #85
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
@addaleax
Copy link
Contributor Author

Landed in 1f66e8b...c4663f3 :)

@addaleax addaleax closed this Sep 30, 2017
@addaleax addaleax deleted the workers-handlecleanup branch September 30, 2017 12:58
jasnell pushed a commit to jasnell/node that referenced this pull request Oct 1, 2017
Original PR: ayojs/ayo#85

> Previously, handles would not be closed when the current `Environment`
> stopped, which is acceptable in a single-`Environment`-per-process
> situation, but would otherwise create memory and file descriptor
> leaks.

> PR-URL: ayojs/ayo#85
> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
jasnell pushed a commit to jasnell/node that referenced this pull request Oct 1, 2017
Original PR: ayojs/ayo#85

> This allows easier tracking of whether there are active `ReqWrap`s.

> PR-URL: ayojs/ayo#85
> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
jasnell pushed a commit to jasnell/node that referenced this pull request Oct 1, 2017
Original PR: ayojs/ayo#85

> Workers cannot shut down while requests are open, so keep a counter
> that is increased whenever libuv requests are made and decreased
> whenever their callback is called.

> PR-URL: ayojs/ayo#85
> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
@addaleax addaleax added the worker label Oct 8, 2017
addaleax added a commit to nodejs/node that referenced this pull request May 14, 2018
Previously, handles would not be closed when the current `Environment`
stopped, which is acceptable in a single-`Environment`-per-process
situation, but would otherwise create memory and file descriptor
leaks.

Also, introduce a generic way to close handles via the
`Environment::CloseHandle()` function, which automatically keeps
track of whether a close callback has been called yet or not.

Many thanks for Stephen Belanger for reviewing the original version of
this commit in the Ayo.js project.

Refs: ayojs/ayo#85
PR-URL: #19377
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
addaleax added a commit to nodejs/node that referenced this pull request May 14, 2018
This allows easier tracking of whether there are active `ReqWrap`s.

Many thanks for Stephen Belanger for reviewing the original version of
this commit in the Ayo.js project.

Refs: ayojs/ayo#85
PR-URL: #19377
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
addaleax added a commit to nodejs/node that referenced this pull request May 14, 2018
Workers cannot shut down while requests are open, so keep a counter
that is increased whenever libuv requests are made and decreased
whenever their callback is called.

This also applies to other embedders, who may want to shut down
an `Environment` instance early.

Many thanks for Stephen Belanger for reviewing the original version of
this commit in the Ayo.js project.

Fixes: #20517
Refs: ayojs/ayo#85
PR-URL: #19377
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants