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: regression with napi_delete_async_work since v10.2.0 #20966

Closed
nstepien opened this issue May 25, 2018 · 11 comments
Closed

n-api: regression with napi_delete_async_work since v10.2.0 #20966

nstepien opened this issue May 25, 2018 · 11 comments
Assignees
Labels
node-api Issues and PRs related to the Node-API.

Comments

@nstepien
Copy link
Contributor

  • Version: v10.2.1
  • Platform: any
  • Subsystem: n-api

I'm experimenting with n-api in a branch of iltorb: nstepien/iltorb#70
I added calls to napi_delete_async_work after forgetting to make use of it, but I ended up getting rogue segmentation faults.

The tests pass on previous versions of Node on various CI, and also on Node v10.1.0 locally, but not Node v10.2.0.
Removing the calls to napi_delete_async_work seems to appease Node v10.2.x.

@hashseed
Copy link
Member

@gabrielschulhof gabrielschulhof self-assigned this May 31, 2018
@kfarnung kfarnung added the node-api Issues and PRs related to the Node-API. label May 31, 2018
@gabrielschulhof
Copy link
Contributor

@MayhemYDG can you create a minimum test case to illustrate the problem?

@nstepien
Copy link
Contributor Author

nstepien commented Jun 4, 2018

@gabrielschulhof I'm trying to create a minimum test case from scratch, but it's not failing unfortunately...
There must be more to it but I don't know where to look. It only happens on Node 10.2.0+.

@gabrielschulhof
Copy link
Contributor

gabrielschulhof commented Jun 4, 2018 via email

@gabrielschulhof
Copy link
Contributor

@MayhemYDG https://gist.github.com/gabrielschulhof/4d01d88a75df33981511304162c4a063 crashes when built against master, but runs fine prior to commit c072057.

@gabrielschulhof
Copy link
Contributor

This is a bug we've fixed before. Before calling the _complete callback we must back up the env, because the copy stored inside the wrapper class gets lost when the wrapper class gets freed as part of napi_delete_async_work().

@gabrielschulhof
Copy link
Contributor

Actually, we've fixed it before, but not with async work: 1a5a19d 🙂

gabrielschulhof pushed a commit to gabrielschulhof/node that referenced this issue Jun 6, 2018
We must back up the value of `_env` before calling the async work
complete callback, because the complete callback may delete the
instance in which `_env` is stored by calling `napi_delete_async_work`,
and because we need to use it after the complete callback has
completed.

Fixes: nodejs#20966
targos pushed a commit that referenced this issue Jun 7, 2018
We must back up the value of `_env` before calling the async work
complete callback, because the complete callback may delete the
instance in which `_env` is stored by calling `napi_delete_async_work`,
and because we need to use it after the complete callback has
completed.

Fixes: #20966
PR-URL: #21129
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
@s-h-a-d-o-w
Copy link

Are you sure this fix resolved everything? Because my simple test (https://github.com/s-h-a-d-o-w/napi-test) still crashes at the call to napi_delete_async_work - using v10.5.0.

@gabrielschulhof
Copy link
Contributor

@s-h-a-d-o-w I'll try to reproduce the crash.

@gabrielschulhof
Copy link
Contributor

@s-h-a-d-o-w at https://github.com/s-h-a-d-o-w/napi-test/blob/master/src/napi_init.cc#L103-L106 you assign work into data->work before passing work into napi_create_async_work() so that it might become initialized.

If you move data->work = work after napi_create_async_work() the segfault will be resolved.

@s-h-a-d-o-w
Copy link

Ahhh! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
node-api Issues and PRs related to the Node-API.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants