-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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: back up env before async work finalize #21129
n-api: back up env before async work finalize #21129
Conversation
I'm not sure if it makes any sense to add a test like this one, but finite. |
Considering this fixes a regression, I'd say a test should be added. |
@MayhemYDG the problem is it's a memory corruption regression, so a 100% reliable test is hard to create. After all, when c072057 introduced the regression, the async work test which we already have should have segfaulted but didn't. My only thought with the above comment was to add a second test which essentially runs the first test over and over and over, because that's what I used for reproducing. But you're right - I think I'll add a test like the one in the gist, with, say, 500 iterations. Hopefully in that many iterations it will crash if we ever again have such a bug. |
18a98d9
to
2853b40
Compare
Well, the test I added crashes before the fix and passes after the fix, so FWIW, it captures the fix. |
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.
LGTM
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.
LGTM
2853b40
to
a3b4c9e
Compare
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
a3b4c9e
to
c7b1950
Compare
sigh ... forgot to set the name of the async context - weird that it did not throw in debug mode O_o Here's another CI: https://ci.nodejs.org/job/node-test-pull-request/15273/ |
@gabrielschulhof |
I'm +1 to land this after only 40h so it make it into 10.4.0, since the most significant stakeholders are aware of this. |
@refack OK, landing it then. |
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 <apapirovski@mac.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
landed in 991f406 |
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 <apapirovski@mac.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Should this be backported to |
@MylesBorins this actually fixes a regression introduced by c072057, so, unless we backport that commit too, we need not backport this commit. As it stands, it doesn't look like that commit was backported to v8.x. |
We must back up the value of
_env
before calling the async workcomplete callback, because the complete callback may delete the
instance in which
_env
is stored by callingnapi_delete_async_work
,and because we need to use it after the complete callback has
completed.
Fixes: #20966
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes