Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

node-api: force env shutdown deferring behavior#37303

Closed
gabrielschulhof wants to merge 5 commits into
nodejs:masternodejs/node:masterfrom
gabrielschulhof:node-api-double-free-ref2gabrielschulhof/node:node-api-double-free-ref2Copy head branch name to clipboard
Closed

node-api: force env shutdown deferring behavior#37303
gabrielschulhof wants to merge 5 commits into
nodejs:masternodejs/node:masterfrom
gabrielschulhof:node-api-double-free-ref2gabrielschulhof/node:node-api-double-free-ref2Copy head branch name to clipboard

Conversation

@gabrielschulhof

Copy link
Copy Markdown
Contributor

The finalizer normally never gets called while a reference is strong.
However, during environment shutdown all finalizers must get called. In
order to unify the deferring behavior with that of a regular
finalization, we must force the reference to be weak when we call its
finalizer during environment shutdown.

Fixes: #37236
Co-authored-by: @legendecas

@gabrielschulhof gabrielschulhof added the node-api Issues and PRs related to the Node-API. label Feb 10, 2021
@nodejs-github-bot nodejs-github-bot added the c++ Issues and PRs that require attention from people who are familiar with C++. label Feb 10, 2021
@gabrielschulhof gabrielschulhof force-pushed the node-api-double-free-ref2 branch from 53f6c32 to cd3e2d1 Compare February 10, 2021 07:30
@RaisinTen

Copy link
Copy Markdown
Member

I think we should add this in the commit message too:

Fixes: https://github.com/nodejs/node/issues/36868

@gabrielschulhof

Copy link
Copy Markdown
Contributor Author

@RaisinTen I'm not 100% sure that the crash is the same. In test_worker_terminate_finalization the reference is weakened before it is deleted, whereas the problem fixed here is the self-deletion during environment teardown of a strong reference.

test_worker_terminate_finalization originally caused a leak which was fixed in c822ba7. Now, if it crashes intermittently, this PR may fix it, but I think we should keep #36868 open to remind ourselves to check on its flakiness.

@gabrielschulhof

Copy link
Copy Markdown
Contributor Author

@RaisinTen it sounds like @mhdawson tried to reproduce #36868 and was unable to do so. Therefore I think we should close #36868 unless the test in question remains flaky.

Comment thread src/js_native_api_v8.cc
Comment thread src/js_native_api_v8.cc Outdated
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@mhdawson mhdawson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

nodejs-github-bot commented Feb 13, 2021

Copy link
Copy Markdown
Collaborator

@mhdawson

Copy link
Copy Markdown
Member

@gabrielschulhof I think @legendecas may be away for a few days and I'm thinking it might still be good to wait for him to have a look as well. What do you think?

@gabrielschulhof

Copy link
Copy Markdown
Contributor Author

@mhdawson OK.

@legendecas

Copy link
Copy Markdown
Member

@gabrielschulhof PR wise looks good to me. However, I may have been mistaken on the test case of #37236 (comment). I've tried the PR on my internal case and it does crash regardlessly.

@gabrielschulhof

Copy link
Copy Markdown
Contributor Author

@legendecas if it still crashes, can you create a test case we can use here? You can even push it to my branch.

Gabriel Schulhof and others added 5 commits February 18, 2021 07:53
The finalizer normally never gets called while a reference is strong.
However, during environment shutdown all finalizers must get called. In
order to unify the deferring behavior with that of a regular
finalization, we must force the reference to be weak when we call its
finalizer during environment shutdown.

Fixes: nodejs#37236
Co-authored-by: Chengzhong Wu <legendecas@gmail.com>
@gabrielschulhof gabrielschulhof force-pushed the node-api-double-free-ref2 branch from 6415c99 to 21e5b1d Compare February 18, 2021 15:54
@gabrielschulhof

Copy link
Copy Markdown
Contributor Author

Rebased.

@gabrielschulhof

Copy link
Copy Markdown
Contributor Author

@legendecas P.S.: your original repro (https://github.com/legendecas/repro-napi-v8impl-refbase-double-free) no longer crashes with this PR.

@legendecas legendecas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@gabrielschulhof it's true. This PR does fix a crash case. I'll try to dig out the stable re-production on the one with weak references.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

gabrielschulhof pushed a commit that referenced this pull request Feb 19, 2021
The finalizer normally never gets called while a reference is strong.
However, during environment shutdown all finalizers must get called. In
order to unify the deferring behavior with that of a regular
finalization, we must force the reference to be weak when we call its
finalizer during environment shutdown.

Fixes: #37236
Co-authored-by: Chengzhong Wu <legendecas@gmail.com>
PR-URL: #37303
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
@gabrielschulhof gabrielschulhof deleted the node-api-double-free-ref2 branch February 19, 2021 04:33
@gabrielschulhof

Copy link
Copy Markdown
Contributor Author

Landed in 03806a0.

targos pushed a commit that referenced this pull request Feb 28, 2021
The finalizer normally never gets called while a reference is strong.
However, during environment shutdown all finalizers must get called. In
order to unify the deferring behavior with that of a regular
finalization, we must force the reference to be weak when we call its
finalizer during environment shutdown.

Fixes: #37236
Co-authored-by: Chengzhong Wu <legendecas@gmail.com>
PR-URL: #37303
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
gabrielschulhof pushed a commit to gabrielschulhof/node that referenced this pull request Mar 6, 2021
The finalizer normally never gets called while a reference is strong.
However, during environment shutdown all finalizers must get called. In
order to unify the deferring behavior with that of a regular
finalization, we must force the reference to be weak when we call its
finalizer during environment shutdown.

Fixes: nodejs#37236
Co-authored-by: Chengzhong Wu <legendecas@gmail.com>
PR-URL: nodejs#37303
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
gabrielschulhof pushed a commit to gabrielschulhof/node that referenced this pull request Mar 19, 2021
The finalizer normally never gets called while a reference is strong.
However, during environment shutdown all finalizers must get called. In
order to unify the deferring behavior with that of a regular
finalization, we must force the reference to be weak when we call its
finalizer during environment shutdown.

Fixes: nodejs#37236
Co-authored-by: Chengzhong Wu <legendecas@gmail.com>
PR-URL: nodejs#37303
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
gabrielschulhof pushed a commit to gabrielschulhof/node that referenced this pull request Mar 19, 2021
The finalizer normally never gets called while a reference is strong.
However, during environment shutdown all finalizers must get called. In
order to unify the deferring behavior with that of a regular
finalization, we must force the reference to be weak when we call its
finalizer during environment shutdown.

Fixes: nodejs#37236
Co-authored-by: Chengzhong Wu <legendecas@gmail.com>
PR-URL: nodejs#37303
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
gabrielschulhof pushed a commit to gabrielschulhof/node that referenced this pull request Mar 26, 2021
The finalizer normally never gets called while a reference is strong.
However, during environment shutdown all finalizers must get called. In
order to unify the deferring behavior with that of a regular
finalization, we must force the reference to be weak when we call its
finalizer during environment shutdown.

Fixes: nodejs#37236
Co-authored-by: Chengzhong Wu <legendecas@gmail.com>
PR-URL: nodejs#37303
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
targos pushed a commit to gabrielschulhof/node that referenced this pull request Apr 24, 2021
The finalizer normally never gets called while a reference is strong.
However, during environment shutdown all finalizers must get called. In
order to unify the deferring behavior with that of a regular
finalization, we must force the reference to be weak when we call its
finalizer during environment shutdown.

Fixes: nodejs#37236
Co-authored-by: Chengzhong Wu <legendecas@gmail.com>
PR-URL: nodejs#37303
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
targos pushed a commit that referenced this pull request Apr 26, 2021
The finalizer normally never gets called while a reference is strong.
However, during environment shutdown all finalizers must get called. In
order to unify the deferring behavior with that of a regular
finalization, we must force the reference to be weak when we call its
finalizer during environment shutdown.

Fixes: #37236
Co-authored-by: Chengzhong Wu <legendecas@gmail.com>
PR-URL: #37303
Backport-PR-URL: #37802
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
@danielleadams danielleadams mentioned this pull request May 3, 2021
legendecas added a commit to legendecas/node that referenced this pull request Mar 29, 2022
The finalizer normally never gets called while a reference is strong.
However, during environment shutdown all finalizers must get called. In
order to unify the deferring behavior with that of a regular
finalization, we must force the reference to be weak when we call its
finalizer during environment shutdown.

Fixes: nodejs#37236
Co-authored-by: Chengzhong Wu <legendecas@gmail.com>
PR-URL: nodejs#37303
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
richardlau pushed a commit that referenced this pull request Mar 30, 2022
The finalizer normally never gets called while a reference is strong.
However, during environment shutdown all finalizers must get called. In
order to unify the deferring behavior with that of a regular
finalization, we must force the reference to be weak when we call its
finalizer during environment shutdown.

Fixes: #37236
Co-authored-by: Chengzhong Wu <legendecas@gmail.com>
PR-URL: #37303
Backport-PR-URL: #42512
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
@richardlau richardlau mentioned this pull request Mar 30, 2022
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.

Crash on node api add-on finalization

6 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.