Skip to content

ffi: fix handle leak in fast buffer arguments - #66867

Open
trivikr wants to merge 1 commit into
nodejs:mainfrom
trivikr:ffi-fast-buffer-path-leak
Open

trivikr wants to merge 1 commit into
nodejs:mainfrom
trivikr:ffi-fast-buffer-path-leak

Conversation

@trivikr

@trivikr trivikr commented Oct 20, 2026

Copy link
Copy Markdown
Member

Fixes: #66866

node_ffi_fast_buffer_data() runs inside a V8 Fast API call, where no HandleScope is open. It calls ArrayBufferView::Buffer(), which created a Local in the caller's scope on every optimized call. Over 2e7 calls, RSS grew from 50 MB to 675 MB.

This opens one HandleScope for the whole helper, matching Node's other fast callbacks. The new test uses v8.queryObjects() to check that optimized calls don't keep backing stores alive.


Assisted-by: claude:opus-5.5

node_ffi_fast_buffer_data() runs inside a V8 Fast API call, where no
HandleScope is open. ArrayBufferView::Buffer() created a Local on
every optimized call, which accumulated in the caller's scope until
the current synchronous run ended. Open one HandleScope for the whole
helper, matching Node's other fast callbacks.

Signed-off-by: Trivikram Kamat <16024985+trivikr@users.noreply.github.com>
Assisted-by: claude:opus-5.5
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/ffi

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Oct 20, 2026
@trivikr trivikr added the ffi Issues and PRs related to experimental Foreign Function Interface support. label Oct 20, 2026
@codecov

codecov Bot commented Oct 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 22.22222% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.50%. Comparing base (56da329) to head (7cf5836).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
src/ffi/fast.cc 22.22% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66867      +/-   ##
==========================================
- Coverage   90.51%   90.50%   -0.02%     
==========================================
  Files         797      797              
  Lines      278221   278213       -8     
  Branches    53463    53458       -5     
==========================================
- Hits       251844   251790      -54     
- Misses      16763    16799      +36     
- Partials     9614     9624      +10     
Files with missing lines Coverage Δ
src/ffi/fast.cc 77.20% <22.22%> (+7.25%) ⬆️

... and 35 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@trivikr trivikr added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Oct 20, 2026
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++. ffi Issues and PRs related to experimental Foreign Function Interface support. needs-ci PRs that need a full CI run. request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ffi: fast buffer path leaks V8 handles on every optimized call

2 participants