Skip to content
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

dgram: tracking unrefdness of dgram sockets #5828

Closed
wants to merge 2 commits into from

Conversation

thlorenz
Copy link
Contributor

Affected core subsystem

dgram

Description of change

  • initializing _unref to false when the socket is created
  • updating that value each time either unref() or ref() is invoked
    on it
  • this mirrors the implementation in lib/net.js
  • adding test to check unrefdness tracking

This PR goes together with the same change applied to child_process ( #5827 )

R= @Fishrock123
R= @trevnorris

- initializing `_unref` to `false` when the socket is created
- updating that value each time either `unref()` or `ref()` is invoked
  on it
- this mirrors the implementation in `lib/net.js`
- adding test to check unrefdness tracking
@mscdex mscdex added the dgram Issues and PRs related to the dgram subsystem / UDP. label Mar 21, 2016
@mscdex
Copy link
Contributor

mscdex commented Mar 21, 2016

I'm curious, why add this and the child_process changes if it's a private variable? Is it actually checked for somewhere else in the code base?

@thlorenz
Copy link
Contributor Author

@mscdex This is useful for tools that show pending async actions in the process and need to show if they are keeping the process running or not.
As mentioned in the PR message in lib/net.js we are currently tracking this property so it makes sense to do so for other async activity handles as well.

@cjihrig
Copy link
Contributor

cjihrig commented Mar 21, 2016

LGTM. Again, would substitute assert.strictEqual() for assert.ok().

@thlorenz
Copy link
Contributor Author

@cjihrig as in assert.strictEqual(sock._unref, true) for instance?
I looked at similar tests (with truthy assertions) and saw ok being used a lot.
However if we're trying to change that in general I can adapt the tests.

@cjihrig
Copy link
Contributor

cjihrig commented Mar 21, 2016

Yes, like that. I think it's a little more readable, with the state toggling back and forth. ok() also only checks truthiness, instead of strict Boolean values.

@jasnell jasnell added the semver-minor PRs that contain new features and should be released in the next minor version. label Mar 21, 2016
@Fishrock123
Copy link
Contributor

Been thinking about this sort of thing for a while, I think it would be best for every handle to have this sort of property in c++, accessible to JS, if possible.

@thlorenz
Copy link
Contributor Author

@Fishrock123 until then we should still get this in IMO, so we are aligned with the info that's exposed by lib/net.js. We can remove all _unref tracking once we are doing this for handles directly.

@Fishrock123
Copy link
Contributor

@thlorenz Problem is, we might not be able to remove the _unref for like 6 months or even a year or more.

@thlorenz
Copy link
Contributor Author

@Fishrock123 that is a valid concern, but the same is true for net.js.
This and the related PR just make things consistent which is better IMO. It's not like the concept of tracking _unref is introduced here.
Also it may be more than 6 months until we get the change to do this on the handle directly and until then the tools have nothing to go by if we don't expose this info via an _unref property.

@vkurchatkin
Copy link
Contributor

-1. If it's useful, it should be public

@mscdex
Copy link
Contributor

mscdex commented Mar 21, 2016

I think I am -1 on this as well. We should not be adding underscore-prefixed properties that we are encouraging end users to use as public/documented properties.

Either don't add it at all or remove the underscore and document it.

@thlorenz
Copy link
Contributor Author

-1. If it's useful, it should be public

Agreed, just trying to match the implementation in net.js which has _unrefd as well.
However we could make this public ... in the meantime I'd like to see if @Fishrock123's #5834 solves this in a better way.

Fishrock123 added a commit to Fishrock123/node that referenced this pull request Apr 7, 2016
This allows third-party tools to check whether or not a handle that
can be unreferenced is unreferenced at a particular time.
Notably, this should be helpful for inspection via AsyncWrap.

Also, this is useful even to node's internals, particularly timers.

Refs: nodejs#5828
Refs: nodejs#5827
PR-URL: nodejs#5834
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
@jasnell
Copy link
Member

jasnell commented Apr 18, 2016

@nodejs/ctc ... we've had one LGTM and a couple -1's on this. Can we get additional review?

@cjihrig
Copy link
Contributor

cjihrig commented Apr 18, 2016

Is this trumped by #5834 and #6204?

@jasnell
Copy link
Member

jasnell commented Apr 20, 2016

Not sure, @Fishrock123 ?

@indutny
Copy link
Member

indutny commented Apr 20, 2016

-1, sorry

@jasnell
Copy link
Member

jasnell commented Apr 20, 2016

Given the -1's and the discussion, then, I'm closing this. Can reopen if necessary.

@jasnell jasnell closed this Apr 20, 2016
evanlucas pushed a commit that referenced this pull request May 17, 2016
This allows third-party tools to check whether or not a handle that
can be unreferenced is unreferenced at a particular time.
Notably, this should be helpful for inspection via AsyncWrap.

Also, this is useful even to node's internals, particularly timers.

Refs: #5828
Refs: #5827
PR-URL: #5834
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dgram Issues and PRs related to the dgram subsystem / UDP. semver-minor PRs that contain new features and should be released in the next minor version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants