Skip to content

Plugin RPC calls retain AbortSignal.any WeakCell bookkeeping after completion #7595

Closed

Description

@mistakeknot

Summary

A bb server that runs a plugin making steady RPC calls grows its heap without bound. Each call that carries a caller signal links that signal to the plugin's long-lived stopping signal with AbortSignal.any, and nothing unlinks it when the call finishes. Expected: a finished call leaves nothing behind on the plugin's stopping signal.

Versions and environment

  • Observed in production on a downstream fork of bb 0.49.0 (version string 0.49.0+aleph.0.10.0, installed from a source build), Node 22.23.4, Ubuntu 24.04.5 LTS, Linux 6.8. The leaking line is unchanged in bb main at da3e60b, so this is not fork-specific.
  • Mechanism reproduced on Node 22.23.4, Ubuntu 24.04.5 LTS, against bb source at da3e60b.
  • No provider involved.

Steps to reproduce

Steps to reproduce

Repro status: the mechanism reproduces in isolation (below) and with a unit test at the code path. A stock bb release server was not run for hours to measure it end to end; the production numbers in Evidence come from the fork build above.

  1. Run this isolated script with Node 22.23.4. It does not start bb or read application data. The loop uses the same composition as invokeWrapped.
node --expose-gc --input-type=module <<'JS'
import { getHeapSnapshot } from "node:v8";
import { setTimeout as delay } from "node:timers/promises";
async function count() {
  for (let i = 0; i < 5; i++) {
    global.gc();
    await delay(20);
  }
  const chunks = [];
  for await (const chunk of getHeapSnapshot()) chunks.push(chunk);
  const heap = JSON.parse(Buffer.concat(chunks).toString());
  const fields = heap.snapshot.meta.node_fields;
  const width = fields.length, name = fields.indexOf("name");
  let cells = 0;
  for (let i = 0; i < heap.nodes.length; i += width)
    if (heap.strings[heap.nodes[i + name]] === "system / WeakCell") cells++;
  return cells;
}
const lifetime = new AbortController();
const before = await count();
for (let i = 0; i < 5000; i++)
  AbortSignal.any([new AbortController().signal, lifetime.signal]);
const after = await count();
console.log(JSON.stringify({before, after, delta: after-before, lifetimeAborted:lifetime.signal.aborted}));
JS
  1. To see it in a server: keep a plugin loaded, make repeated plugin RPC calls that pass a caller signal, then compare V8 heap snapshots after GC and inspect the WeakCell retainers that target that plugin instance's stopping signal.

Narrowing: a plugin reload is not needed to see it. Per the code at the link above, calls without a caller signal use the stopping signal directly and create no composite (read from the code, not measured).

Expected vs actual

## Expected vs actual

Expected: finished calls leave no per-call bookkeeping on the plugin's live stopping signal.

Actual (isolated script, verbatim):


{"before":12,"after":5012,"delta":5000,"lifetimeAborted":false}


Counts vary by Node/V8 version. The five GC/wait rounds let finalization callbacks clean up temporary cells before counting.

Evidence

Observed:

  • A production heap snapshot after 10.5 hours of uptime had about 1.40 million WeakCells; 98% targeted one plugin stopping signal through this composition. The plugin made about 36 RPC calls per second. Measured with a V8 heap snapshot and a retainer count; at an estimated 176 bytes per call that is about 20 MB per hour (an estimate from the cell count, not a measured before/after slope).
  • With the composition replaced by a removable link that is disposed when each call ends, the isolated script's WeakCell delta over 5,000 calls was zero.

Cause (inferred from the code): every invocation with a caller signal creates an AbortSignal.any composite against the same long-lived signal at plugin-runtime.ts#L908-L914, and completion never unlinks it.

Investigation and the fork's fix: mistakeknot#240 (links the two signals with removable listeners, keeps abort reasons, and disposes the link in invokeWrapped's finally). One behavior change to note: the link then covers only an active call, so a handler that keeps the signal after returning no longer receives later caller or plugin aborts through it. A fix PR for bb with cancellation, disposal, repeated-call and RPC settlement tests will follow and link this issue.

What you ruled out

Suggested priority and effort (optional)

Hits any long-running server whose plugins make frequent RPC calls with caller signals; memory grows until restart, which is the only workaround. No data or work is lost. Effort is small: a ready fix of about 30 lines plus tests.

Checks

  • I reproduced this on the latest release or on main, or I say above that I could not.
  • I searched open and closed issues for the same problem.
  • If an agent wrote this, the body ends with > AGENT GENERATED and links the thread or report.

AGENT GENERATED

Activity

  1. added theissue type on Nov 15, 2026
  2. added
    plugins
    confirmed-repro
    on Nov 15, 2026
  3. bb-slop-cop commented on Nov 15, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    • Classification: Bug · Priority High · Effort Low; plugins, perf, confirmed-repro. All classifications were missing and are now applied; no existing values were replaced.
    • Report: Reproduction and root-cause report.
    • Verdict: REPRODUCED · root-cause confidence high.
    • Evidence: Two clean trusted-main checkouts at da3e60b81 each retained 256 additional WeakCells after 256 completed signalled RPCs; 256 control calls without caller signals retained none. The plugin stayed loaded and unaborted.
    • Root cause: Per-call AbortSignal.any composition registers bookkeeping against the long-lived plugin stopping signal; invocation settlement does not dispose that composition.
    • Regression: The report includes the complete service-level test, plugin-invocation-retention.test.ts, and its expected failure in both checkouts. Production memory-growth rates were not measured.
    • No PR: Completion-scoped cleanup changes late cancellation for handler-retained signals, as demonstrated by the test. Deciding that signal-lifetime contract exceeds the automatic simple-fix gate; no fix branch was pushed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-reproperfplugins

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions