Detecting memory leaks through shared function context

Open
#281 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
javascript, nodejs
Domain
observability

Research direction

Start with the linked diagnostics-summit document and the heap-snapshot reconstruction approach described here; no repository files or tests are named. Establish how heap snapshots can identify objects retained by a shared function context, and define a reproducible result that demonstrates the detected pattern.

Written by the indexing model from the issue text.

Description

blind-spot never stale

This was discussed at the diagnostics summit, and I want to take the discussion here. The document I referred to is this, by my colleague @jakobkummerow.

The gist of the problem is:

const f = (function() {
  let a = {};
  let b = {};
  let c = ()=>a;  // forces a to be context-allocated.
  let d = ()=>b;  // forces b to be context-allocated.
  return d;  // the function context escapes and is kept alive.
})();

The object assigned to a is no longer accessible though JavaScript, but is kept alive because it is allocated onto the same context as b, which remains accessible through d.

Detecting this pattern at runtime would require the VM to keep track of additional meta-data, which does not pay off. However, we could, based on the information from a heap snapshot reconstruct missing metadata and detect this pattern.

Dominant language
No language data
Stars
550
Forks
69
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nodejs/diagnostics

All issues in nodejs/diagnostics

Similar issues

More Observability & SRE issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.