Bump node-addon-api to fix memory leak #2436#2562
Open
iurisilvio wants to merge 2 commits intoAutomattic:masterfrom
Open
Bump node-addon-api to fix memory leak #2436#2562iurisilvio wants to merge 2 commits intoAutomattic:masterfrom
node-addon-api to fix memory leak #2436#2562iurisilvio wants to merge 2 commits intoAutomattic:masterfrom
Conversation
Collaborator
|
Great find! That tracks perfectly with what we discussed in the issue, and it looks like we are good to upgrade since we don't support node 16. The tests are failing, though. |
Author
|
Thank you for running the tests, I didn't run them local before! Now I ran it on Mac and Linux, reproduced the failures local, I hope my last commit fix all of them. 🙏🏻 |
Author
|
Nice, all green now! 💚 Looking forward to have it reviewed/merged/released! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix memory leak from deferred N-API weak reference callbacks
Fixes #2436
Problem
Since the NAN -> N-API migration (v3.0.0),
ObjectWrapdestructors (which free cairo surfaces) are deferred to the nextSetImmediateinstead of running during GC. In server environments where the event loop is always busy, these destructors never fire and memory grows indefinitely.This was reported upstream in nodejs/node-addon-api#1140 and fixed in nodejs/node#42651 by introducing
node_api_nogc_finalize, a finalizer that runs directly during GC for native-only cleanup.Fix
node-addon-apifrom 7.x to 8.x (which usesnode_api_nogc_finalizeforObjectWrap::FinalizeCallback)NAPI_EXPERIMENTALtobinding.gypdefines (required to enableNODE_API_EXPERIMENTAL_HAS_POST_FINALIZERin Node's headers)No code changes,
node-addon-api8.x automatically routesObjectWrapdestructor callbacks through the nogc finalizer path when the flag is set.I don't fully understand the impact of
node-addon-apiupgrade or enablingNAPI_EXPERIMENTAL.Before / After
200 requests decoding 3000x2000 JPEG images into thumbnails: