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

n-api: napi_make_callback emit async init event with resource of async_context #32930

Closed
wants to merge 1 commit into from

Conversation

legendecas
Copy link
Member

@legendecas legendecas commented Apr 19, 2020

instead of emitting async init with the receiver of the callback.

Fixes: #32898
Related: #32928

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. node-api Issues and PRs related to the Node-API. labels Apr 19, 2020
@legendecas legendecas marked this pull request as ready for review April 21, 2020 02:17
@Qard
Copy link
Member

Qard commented Apr 21, 2020

This duplicates a lot of code from AsyncWrap. It also appears to be a major breaking change to N-API which I was hoping to avoid as it makes it difficult to backport executionAsyncResource related code. Not sure how I feel about this. 😟

@legendecas
Copy link
Member Author

This duplicates a lot of code from AsyncWrap.

Yes, this is for AsyncWrap not suitable in the case since the resource object in the N-API may have no internal slot, which fails the BaseObject's assertion.

It also appears to be a major breaking change to N-API

Could you elaborate on how this would be breaking to existing N-API codes? It seems to me doesn't break codes and behaviors? (They are not working as expected already).

@Qard
Copy link
Member

Qard commented Apr 22, 2020

cc @nodejs/n-api @nodejs/diagnostics

The approach seems reasonable. Could use some more review from people that know n-api better though, especially around ABI impact.

src/node_api.cc Outdated Show resolved Hide resolved
src/node_api.cc Outdated Show resolved Hide resolved
@mhdawson
Copy link
Member

I think we discussed this in the last N-API team meeting and @legendecas just needs to find some time to get back to it.

@legendecas legendecas force-pushed the napi_async_context branch 3 times, most recently from eb5fdef to 242acad Compare October 6, 2020 18:15
@legendecas
Copy link
Member Author

@addaleax @mhdawson @Flarna Sorry for the terrible long delay. I've updated the PR, PTAL :)

Copy link
Member

@Qard Qard left a comment

Choose a reason for hiding this comment

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

Overall LGTM, but might be good to do something with that unused resource or people might get confused if they try to use a different resource and it silently ignores it. 🤔

@@ -627,26 +692,19 @@ NAPI_NO_RETURN void napi_fatal_error(const char* location,
}

napi_status napi_open_callback_scope(napi_env env,
napi_value resource_object,
napi_value /** ignored */,
Copy link
Member

Choose a reason for hiding this comment

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

Should we perhaps use the resource_object to warn if it's different than the object contained in the AsyncContext?

Copy link
Member

Choose a reason for hiding this comment

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

@quad I see what you mean, but that might be a breaking change and we don't have breaking changes for N-API methods. If we felt strongly about it we should add a new method without the parameter and doc deprecate the existing method (but not remove of course). I think we did something similar for another API in terms of indicate /** ignored */

Copy link
Member

Choose a reason for hiding this comment

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

I was just thinking a log message warning, no change in behaviour. Is that still considered breaking? Either way, not blocking on that. Just a thought that it'd be nice to have some indicator when the API is used improperly.

Copy link
Member

Choose a reason for hiding this comment

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

To my knowledge node has no logger. Logging to stdout/stderr tends to break command line tools.

But I think we should find a way how to deprecate something in NAPI in a way more visible to users like comments in doc.
I think a compile time warning like it is used for node::MakeCallback would be great.

Copy link
Member Author

@legendecas legendecas Oct 15, 2020

Choose a reason for hiding this comment

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

I think a compile time warning like it is used for node::MakeCallback would be great.

AFAICT, it is not possible to emit compile-time warning without changing the API shapes. i.e. the signature of node::MakeCallback was migrated to the one with an additional parameter async_context. Though in the case of n_api, the deprecation is the parameter in the middle of the parameter list. So a new n-api function without the parameter will be required and the one existing can be deprecated.

Copy link
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

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

LGTM

src/node_api.cc Outdated Show resolved Hide resolved
src/node_api.cc Outdated Show resolved Hide resolved
@aduh95 aduh95 added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Oct 16, 2020
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Oct 16, 2020
@nodejs-github-bot
Copy link
Collaborator

@aduh95 aduh95 added the commit-queue Add this label to land a pull request using GitHub Actions. label Oct 16, 2020
@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

instead of emit async init with receiver of the callback.
@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot
Copy link
Collaborator

@Flarna Flarna added the commit-queue Add this label to land a pull request using GitHub Actions. label Oct 31, 2020
@github-actions github-actions bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Oct 31, 2020
@github-actions
Copy link
Contributor

Landed in 5da2512...3a7537d

@github-actions github-actions bot closed this Oct 31, 2020
nodejs-github-bot pushed a commit that referenced this pull request Oct 31, 2020
instead of emit async init with receiver of the callback.

PR-URL: #32930
Fixes: #32898
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
@legendecas legendecas deleted the napi_async_context branch October 31, 2020 06:29
targos pushed a commit that referenced this pull request Nov 3, 2020
instead of emit async init with receiver of the callback.

PR-URL: #32930
Fixes: #32898
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
@targos targos mentioned this pull request Nov 3, 2020
BethGriggs pushed a commit that referenced this pull request Dec 8, 2020
instead of emit async init with receiver of the callback.

PR-URL: #32930
Fixes: #32898
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
BethGriggs pushed a commit that referenced this pull request Dec 10, 2020
instead of emit async init with receiver of the callback.

PR-URL: #32930
Fixes: #32898
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
@BethGriggs BethGriggs mentioned this pull request Dec 10, 2020
BethGriggs pushed a commit that referenced this pull request Dec 15, 2020
instead of emit async init with receiver of the callback.

PR-URL: #32930
Fixes: #32898
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
tniessen added a commit that referenced this pull request Aug 15, 2023
nodejs-github-bot pushed a commit that referenced this pull request Aug 17, 2023
Refs: #32930
PR-URL: #49180
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
UlisesGascon pushed a commit that referenced this pull request Sep 10, 2023
Refs: #32930
PR-URL: #49180
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
targos pushed a commit that referenced this pull request Nov 27, 2023
Refs: #32930
PR-URL: #49180
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
sercher added a commit to sercher/graaljs that referenced this pull request Apr 25, 2024
Refs: nodejs/node#32930
PR-URL: nodejs/node#49180
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
sercher added a commit to sercher/graaljs that referenced this pull request Apr 25, 2024
Refs: nodejs/node#32930
PR-URL: nodejs/node#49180
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. node-api Issues and PRs related to the Node-API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

n-api: napi_make_callback with async_hooks.executionAsyncResource
8 participants