Skip to content

Conversation

@addaleax
Copy link
Member

@addaleaxaddaleax commented Dec 30, 2019

Manage the napi_env refcount from Finalizer instances, as the
finalizer may refer to the napi_env until it is deleted.

Fixes: #31134
Fixes: node-ffi-napi/node-ffi-napi#48

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

Manage the napi_env refcount from Finalizer instances, as the finalizer may refer to the napi_env until it is deleted. Fixes: nodejs#31134Fixes: node-ffi-napi/node-ffi-napi#48
@addaleaxaddaleax added node-api Issues and PRs related to the Node-API. lts-watch-v10.x labels Dec 30, 2019
@nodejs-github-botnodejs-github-bot added the c++ Issues and PRs that require attention from people who are familiar with C++. label Dec 30, 2019
@nodejs-github-bot
Copy link
Collaborator

@addaleaxaddaleax added the wip Issues and PRs that are still a work in progress. label Dec 30, 2019
Trott
Trott previously approved these changes Dec 30, 2019
@TrottTrott dismissed their stale reviewDecember 30, 2019 20:55

test failures

@addaleaxaddaleax removed the wip Issues and PRs that are still a work in progress. label Dec 30, 2019
@nodejs-github-bot
Copy link
Collaborator

@legendecas
Copy link
Member

Just out of curiosity, why wrapped objects by napi_wrap do not surface this issue? I tested against objects been wrapped which has been attached to process object too, it didn't crash on exit.

@addaleax
Copy link
MemberAuthor

@legendecas Because those finalizers are called during the destruction of napi_env, so the napi_env is still accessible at that point, as I understand it.

@nodejs-github-bot
Copy link
Collaborator

@legendecas
Copy link
Member

@addaleax Because those finalizers are called during the destruction of napi_env, so the napi_env is still accessible at that point, as I understand it.

Yeah, there are two lists tracking these references. Wondering if it is possible to track those array buffers in the list too?

@addaleax
Copy link
MemberAuthor

@addaleax Because those finalizers are called during the destruction of napi_env, so the napi_env is still accessible at that point, as I understand it.

Yeah, there are two lists tracking these references. Wondering if it is possible to track those array buffers in the list too?

Well … In an ideal world, I think it would have been cleaner and more consistent for N-API not to just blindly wrap the Node.js C++ Buffer API, and instead only provide the option to create a Buffer using napi_create_typedarray(env, napi_buffer, ...) analogously to napi_create_typedarray(env, napi_uint8_array, ...).

However, the way things currently work is that the N-API methods for dealing with buffers correspond to the C++ Buffer API. That has its own finalization mechanism.

The only way “out” of this that I could see is to try and implement the N-API buffer methods in terms of the regular N-API typed array methods – feel free to do that if you like, but it seems like that’s out of scope for this PR.

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

nodejs-github-bot commented Jan 4, 2020

@addaleax
Copy link
MemberAuthor

Landed in 493faf6

@addaleaxaddaleax closed this Jan 4, 2020
@addaleaxaddaleax deleted the fix-napi-finalizer-env-ref branch January 4, 2020 06:38
addaleax added a commit that referenced this pull request Jan 4, 2020
Manage the napi_env refcount from Finalizer instances, as the finalizer may refer to the napi_env until it is deleted. Fixes: #31134Fixes: node-ffi-napi/node-ffi-napi#48 PR-URL: #31140 Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Rich Trott <[email protected]>
targos pushed a commit that referenced this pull request Jan 6, 2020
Manage the napi_env refcount from Finalizer instances, as the finalizer may refer to the napi_env until it is deleted. Fixes: #31134Fixes: node-ffi-napi/node-ffi-napi#48 PR-URL: #31140 Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Rich Trott <[email protected]>
@BridgeARBridgeAR mentioned this pull request Jan 7, 2020
targos pushed a commit that referenced this pull request Jan 14, 2020
Manage the napi_env refcount from Finalizer instances, as the finalizer may refer to the napi_env until it is deleted. Fixes: #31134Fixes: node-ffi-napi/node-ffi-napi#48 PR-URL: #31140 Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Rich Trott <[email protected]>
@targostargos mentioned this pull request Jan 15, 2020
BethGriggs pushed a commit that referenced this pull request Feb 6, 2020
Manage the napi_env refcount from Finalizer instances, as the finalizer may refer to the napi_env until it is deleted. Fixes: #31134Fixes: node-ffi-napi/node-ffi-napi#48 PR-URL: #31140 Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Rich Trott <[email protected]>
@MylesBorinsMylesBorins mentioned this pull request Feb 8, 2020
Sign up for freeto 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-apiIssues and PRs related to the Node-API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Buffer api error since 13.3.0 Segmentation fault in node 13

7 participants

@addaleax@nodejs-github-bot@legendecas@Trott@gengjiawen@MylesBorins@BethGriggs