GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — AsyncWrap external API improvements by trevnorris · Pull Request #3461 · nodejs/node

Conversation

@trevnorris

@trevnorris trevnorris commented Oct 20, 2015

Copy link
Copy Markdown
Contributor

Few improvements to make the AsyncWrap external API more usable. These include:

  1. Hooks are optional (except the init hook).
  2. All AsyncWrap instances receive a unique id.
  3. Call callback from the AsyncWrap destructor.

R=@bnoordhuis

CI: https://ci.nodejs.org/job/node-test-pull-request/548/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@trevnorris trevnorris added the c++ Issues and PRs that require attention from people who are familiar with C++. label Oct 20, 2015
trevnorris
trevnorris reviewed Oct 20, 2015
View reviewed changes
Comment thread src/async-wrap.cc Outdated

@trevnorris trevnorris Oct 20, 2015

Copy link
Copy Markdown
Contributor Author

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.

Since the init callback is always necessary, will change this to fail if init callback is not passed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jasnell

jasnell commented Oct 21, 2015

Copy link
Copy Markdown
Member

semver-minor or major?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

thefourtheye
thefourtheye reviewed Oct 21, 2015
View reviewed changes
Comment thread src/async-wrap.cc Outdated

@thefourtheye thefourtheye Oct 21, 2015

Copy link
Copy Markdown
Contributor

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.

Earlier if the arguments are not functions, it will throw. This change will ignore the values if they are not functions. Is that okay?

Edit: Ah, I see it now. This is the first point in the PR description.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@thefourtheye

thefourtheye commented Oct 21, 2015

Copy link
Copy Markdown
Contributor

Why do we need the unique ids?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rvagg

rvagg commented Oct 21, 2015

Copy link
Copy Markdown
Member

re semver—so far we've been treating AsyncWrap changes as neither major nor minor but getting all changes in to patch releases because it's sort of in "unofficial" land, undocumented anyway

at some point we have to grow out of that though! @trevnorris do you have a feel for maturity of AsyncWrap? We can't leave it in limbo, it needs to be an official API at some point.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@trevnorris

trevnorris commented Oct 21, 2015

Copy link
Copy Markdown
Contributor Author

@thefourtheye For the new destructed callback. We can't return the instance like we do in the others, so instead we give the id of the instance being destroyed.

@rvagg My recent flurry of PRs regarding async wrap is to address this. I feel like it's almost ready to be made publicly experimental API, but there is still some cleanup that needs to be done. e.g. it can't simply abort if something goes wrong. like right now if any of the callbacks throw the program will simply crash. I did that b/c I honestly have no idea what will happen to the application if execution proceeds after an exception.

There's also the case of timers. Currently none of these are being tracked. While this could be delayed until after making the API public, I have a couple implementation ideas to try out first.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@trevnorris
trevnorris force-pushed the async-id-destruct branch from 20c95fd to c11d56f Compare October 21, 2015 21:42
@trevnorris

trevnorris commented Oct 21, 2015

Copy link
Copy Markdown
Contributor Author

Added test and rebased.

CI: https://ci.nodejs.org/job/node-test-pull-request/556/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@trevnorris
trevnorris force-pushed the async-id-destruct branch from c11d56f to f8a3b16 Compare October 22, 2015 17:45
@rvagg

rvagg commented Oct 25, 2015

Copy link
Copy Markdown
Member

needs someone more qualified than me to review, @nodejs/tracing, @bnoordhuis or @thlorenz perhaps?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

AndreasMadsen
AndreasMadsen reviewed Oct 26, 2015
View reviewed changes
Comment thread src/async-wrap.cc

@AndreasMadsen AndreasMadsen Oct 26, 2015

Copy link
Copy Markdown
Member

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.

why is the function check required? In the reset of the code only init_fn.IsEmpty() is used to check of async-wrap is enabled. The SetupHooks function also checks that init_fn is a function.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@trevnorris trevnorris Oct 26, 2015

Copy link
Copy Markdown
Contributor Author

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.

Currently in AsyncWrap::AsyncWrap we check if the init hook is set. If not then it returns early. If this is the case then bits_ will never be set and no additional callback will ever be called for that object as a result. I can probably rethink the logic, but this seemed the most straight forward for this PR.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@AndreasMadsen

AndreasMadsen commented Oct 26, 2015

Copy link
Copy Markdown
Member

Very awesome with the destructor hook. But how does this fit into the tick/turn logic, does it follow immediately after the post hook in the oncomplete cases?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AndreasMadsen AndreasMadsen mentioned this pull request Oct 26, 2015
[async_hooks] tracking issue nodejs/diagnostics#29
Closed
23 of 27 tasks
@trevnorris

trevnorris commented Oct 26, 2015

Copy link
Copy Markdown
Contributor Author

how does this fit into the tick/turn logic, does it follow immediately after the post hook in the oncomplete cases?

Doesn't have a specific timing. Sometimes the handle is cleaned up on a close() call, and other times it's cleaned up whenever GC gets around to it. It fires whenever the class instance is being destructed, and that can be done manually or be handled automatically.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@trevnorris
trevnorris force-pushed the async-id-destruct branch from f8a3b16 to 1144ed2 Compare October 26, 2015 19:32
@indutny

indutny commented Nov 6, 2015

Copy link
Copy Markdown
Member

LGTM, if CI is green

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@trevnorris
trevnorris force-pushed the async-id-destruct branch from 1144ed2 to 325cb95 Compare November 6, 2015 23:01
@trevnorris

trevnorris commented Nov 6, 2015

Copy link
Copy Markdown
Contributor Author

One final CI after rebase: https://ci.nodejs.org/job/node-test-pull-request/681/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@trevnorris
trevnorris force-pushed the async-id-destruct branch from 325cb95 to 8983ab4 Compare November 6, 2015 23:13
trevnorris added 3 commits November 6, 2015 16:36
@trevnorris
async_wrap: allow some hooks to be optional
a4e9487
Only enforce that the init callback is passed to setupHooks(). The
remaining hooks can be optionally passed.

Throw if async_wrap.enable() runs before setting the init callback or if
setupHooks() is called while async wrap is enabled.

Add test to verify calls throw appropriately.

PR-URL: nodejs#3461
Reviewed-By: Fedor Indutny <[email protected]>
@trevnorris
async_wrap: new instances get uid
80a66ba
New instances of AsyncWrap are automatically assigned a unique id. The
value will be used in future commits to communicate additional
information via the async hooks.

While the largest value we can reliably communicate to JS is 2^53, even
if a new AsyncWrap is created every 100ns the uid won't reach its end
for 28.5 years.

PR-URL: nodejs#3461
Reviewed-By: Fedor Indutny <[email protected]>
@trevnorris
async_wrap: call callback in destructor
bb1bd76
Call a user's callback to notify that the handle has been destroyed.
Only pass the id of the AsyncWrap instance since the object no longer
exists.

The object that's being destructed should never be inspected within the
callback or any time afterward.

This commit make a breaking change. The init callback will now be passed
arguments in the order of provider, id, parent.

PR-URL: nodejs#3461
Reviewed-By: Fedor Indutny <[email protected]>
@trevnorris
trevnorris force-pushed the async-id-destruct branch from 8983ab4 to bb1bd76 Compare November 6, 2015 23:38
@trevnorris
trevnorris merged commit bb1bd76 into nodejs:master Nov 6, 2015
@trevnorris

trevnorris commented Nov 6, 2015

Copy link
Copy Markdown
Contributor Author

All CI failures were Jenkins related.

Landed in a4e9487, 80a66ba and bb1bd76.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@trevnorris

trevnorris commented Nov 6, 2015

Copy link
Copy Markdown
Contributor Author

@jasnell Thoughts on LTS worthy? Since this is technically internal API still, no API breakage.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@trevnorris
trevnorris deleted the async-id-destruct branch November 6, 2015 23:42
trevnorris added a commit that referenced this pull request Nov 7, 2015
@trevnorris @rvagg
async_wrap: allow some hooks to be optional
5d34c81
Only enforce that the init callback is passed to setupHooks(). The
remaining hooks can be optionally passed.

Throw if async_wrap.enable() runs before setting the init callback or if
setupHooks() is called while async wrap is enabled.

Add test to verify calls throw appropriately.

PR-URL: #3461
Reviewed-By: Fedor Indutny <[email protected]>
trevnorris added a commit that referenced this pull request Nov 7, 2015
@trevnorris @rvagg
async_wrap: new instances get uid
eccbec9
New instances of AsyncWrap are automatically assigned a unique id. The
value will be used in future commits to communicate additional
information via the async hooks.

While the largest value we can reliably communicate to JS is 2^53, even
if a new AsyncWrap is created every 100ns the uid won't reach its end
for 28.5 years.

PR-URL: #3461
Reviewed-By: Fedor Indutny <[email protected]>
trevnorris added a commit that referenced this pull request Nov 7, 2015
@trevnorris @rvagg
async_wrap: call callback in destructor
b663d2b
Call a user's callback to notify that the handle has been destroyed.
Only pass the id of the AsyncWrap instance since the object no longer
exists.

The object that's being destructed should never be inspected within the
callback or any time afterward.

This commit make a breaking change. The init callback will now be passed
arguments in the order of provider, id, parent.

PR-URL: #3461
Reviewed-By: Fedor Indutny <[email protected]>
This was referenced Nov 10, 2015
Release proposal: v5.1.0 #3700
Closed
Propose v5.1.0 #3736
Merged
@jasnell jasnell added the lts-watch-v4.x label Nov 13, 2015
@MylesBorins MylesBorins mentioned this pull request Nov 17, 2015
v4.2.2+1 commit candidates nodejs/Release#57
Closed
@MylesBorins

MylesBorins commented Nov 30, 2015

Copy link
Copy Markdown
Contributor

@jasnell @rvagg thoughts on lts? Don't feel qualified to make this decision

fwiw the commits all land cleanly and test / test-addons pass

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rvagg

rvagg commented Nov 30, 2015

Copy link
Copy Markdown
Member

I'm a tentative +1 on getting the asyncwrap improvements into v4.x but I think this might be worth discussing in either a CTC or LTS WG meeting because the API is getting close to being finalised and documented, how far do we go in keeping it updated in LTS? It's useful but mostly a background feature for everyone but those in the know.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rvagg rvagg mentioned this pull request Nov 30, 2015
AsyncWrap for LTS Argon nodejs/Release#59
Closed
@MylesBorins

MylesBorins commented Dec 15, 2015

Copy link
Copy Markdown
Contributor

@rvagg @trevnorris was a decision reached regarding landing this on 4.x?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rvagg

rvagg commented Dec 15, 2015

Copy link
Copy Markdown
Member

I can't recall exactly but I'm pretty sure we agreed to land AsyncWrap functionality on to v4 but to stop short of announcing it as a major addition—we really just want to get parity where it gets to before it's announced as public in v5/v6 so we don't risk shipping a 1/2 baked version that's not compatible with anything else and is simply technical debt in v4.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rvagg rvagg mentioned this pull request Dec 17, 2015
Release 4.2.4 Planning #4321
Closed
@AndreasMadsen AndreasMadsen mentioned this pull request Dec 28, 2015
Async wrap update - destroy hook and uid nodejs/diagnostics#37
Merged
trevnorris added a commit that referenced this pull request Dec 29, 2015
@trevnorris Myles Borins
async_wrap: allow some hooks to be optional
e6b5119
Only enforce that the init callback is passed to setupHooks(). The
remaining hooks can be optionally passed.

Throw if async_wrap.enable() runs before setting the init callback or if
setupHooks() is called while async wrap is enabled.

Add test to verify calls throw appropriately.

PR-URL: #3461
Reviewed-By: Fedor Indutny <[email protected]>
trevnorris added a commit that referenced this pull request Dec 29, 2015
@trevnorris Myles Borins
async_wrap: new instances get uid
ca8b478
New instances of AsyncWrap are automatically assigned a unique id. The
value will be used in future commits to communicate additional
information via the async hooks.

While the largest value we can reliably communicate to JS is 2^53, even
if a new AsyncWrap is created every 100ns the uid won't reach its end
for 28.5 years.

PR-URL: #3461
Reviewed-By: Fedor Indutny <[email protected]>
trevnorris added a commit that referenced this pull request Dec 29, 2015
@trevnorris Myles Borins
async_wrap: call callback in destructor
dab862f
Call a user's callback to notify that the handle has been destroyed.
Only pass the id of the AsyncWrap instance since the object no longer
exists.

The object that's being destructed should never be inspected within the
callback or any time afterward.

This commit make a breaking change. The init callback will now be passed
arguments in the order of provider, id, parent.

PR-URL: #3461
Reviewed-By: Fedor Indutny <[email protected]>
@MylesBorins

MylesBorins commented Dec 29, 2015

Copy link
Copy Markdown
Contributor

landed in v4.x-staging as ae46a23...dab862f

If there are any concerns about this being in LTS please let me know and I'll back the commits out.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@MylesBorins MylesBorins added land-on-v4.x and removed lts-watch-v4.x labels Dec 29, 2015
@AndreasMadsen

AndreasMadsen commented Dec 29, 2015

Copy link
Copy Markdown
Member

@thealphanerd This was discussed in nodejs/Release#59 (comment)

CTC discussion suggested that AsyncWrap should be brought up to parity with the final version, just not announced as a public and supported API in v4.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AndreasMadsen AndreasMadsen mentioned this pull request Jan 4, 2016
AsyncWrap init hook threw AndreasMadsen/trace#19
Closed
MylesBorins pushed a commit that referenced this pull request Jan 19, 2016
@trevnorris Myles Borins
async_wrap: allow some hooks to be optional
49f16d7
Only enforce that the init callback is passed to setupHooks(). The
remaining hooks can be optionally passed.

Throw if async_wrap.enable() runs before setting the init callback or if
setupHooks() is called while async wrap is enabled.

Add test to verify calls throw appropriately.

PR-URL: #3461
Reviewed-By: Fedor Indutny <[email protected]>
MylesBorins pushed a commit that referenced this pull request Jan 19, 2016
@trevnorris Myles Borins
async_wrap: new instances get uid
a8b45e9
New instances of AsyncWrap are automatically assigned a unique id. The
value will be used in future commits to communicate additional
information via the async hooks.

While the largest value we can reliably communicate to JS is 2^53, even
if a new AsyncWrap is created every 100ns the uid won't reach its end
for 28.5 years.

PR-URL: #3461
Reviewed-By: Fedor Indutny <[email protected]>
MylesBorins pushed a commit that referenced this pull request Jan 19, 2016
@trevnorris Myles Borins
async_wrap: call callback in destructor
5533681
Call a user's callback to notify that the handle has been destroyed.
Only pass the id of the AsyncWrap instance since the object no longer
exists.

The object that's being destructed should never be inspected within the
callback or any time afterward.

This commit make a breaking change. The init callback will now be passed
arguments in the order of provider, id, parent.

PR-URL: #3461
Reviewed-By: Fedor Indutny <[email protected]>
@MylesBorins MylesBorins mentioned this pull request Jan 19, 2016
V4.2.5 proposal #4768
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

c++ Issues and PRs that require attention from people who are familiar with C++.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@trevnorris @jasnell @thefourtheye @rvagg @AndreasMadsen @indutny @MylesBorins
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.