Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

FinalizationRegistry callbacks never run: no host cleanup callback is set

Abierto
#327 5 comentarios 1 reacción 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@veeshi ya está trabajando en esto.

Desde el 19/10/2026.

  • #331 de @veeshi — abierto

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
55/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
javascript, wasm
Área
backend

Línea de trabajo

Start with runtime/event_loop.cpp and the EventLoop::init and EventLoop::run_event_loop entry points named in the proposed fix. Read how the event loop runs js::RunJobs, then compare the SpiderMonkey shell cleanup callback behavior referenced in the issue. Done means queued finalization cleanups run after each microtask checkpoint, with exceptions reported and cleared; verify using the reproduction across repeated calls.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

StarlingMonkey does not call JS::SetHostCleanupFinalizationRegistryCallback, so SpiderMonkey
queues the records of dead FinalizationRegistry targets and nothing ever runs them. The
embedder is expected to run the doCleanup function it is handed (HTML's
HostEnqueueFinalizationRegistryCleanupJob; the SpiderMonkey shell queues it as a task after the
microtask checkpoint, see ShellCleanupFinalizationRegistryCallback / MaybeRunShellTasks in
js/src/shell/js.cpp).

Seen at StarlingMonkey 9dda8ba (the commit ComponentizeJS 0.23.0 pins), SpiderMonkey
FIREFOX_147_0_4_RELEASE_STARLING.

Why it matters beyond user code: the bindings ComponentizeJS generates
(spidermonkey-embedding-splicer/src/bindgen.rs) drop an imported resource handle that was
not disposed explicitly only from a FinalizationRegistry callback. On a long-lived (reused)
instance every such handle stays live until the store's handle limit traps the instance. A
library that evicts a cache from a callback keeps every entry, and each queued record stays in
the GC heap.

Reproduction (a component reused for many calls):

let finalized = 0;
const registry = new FinalizationRegistry(() => { finalized += 1; });
export function handle() {
  registry.register({}, 0);
  const buffer = new Uint8Array(2 << 20); // enough malloc to start full collections
  buffer[0] = 1;
  return `${finalized}`;
}

Expected: the count rises after the first full collections. Actual: 0 on every call (we saw
finalized=0 after 1,000 calls while a WeakRef to a dropped object had been cleared, so
collections do run).

Proposed fix (what we carry as a patch, in runtime/event_loop.cpp):

  • in EventLoop::init, set the callback; it appends doCleanup to a
    PersistentRooted<GCVector<JSFunction *, 0, js::SystemAllocPolicy>> and nothing else
    (it is called during GC, so it must not GC);
  • in EventLoop::run_event_loop, after each js::RunJobs microtask checkpoint, swap the queue
    out and call each function in its own realm; an exception is reported and cleared, not
    propagated; if any ran, loop back for the microtasks they queued.

This runs cleanups as a task after the microtask checkpoint, as the shell does, and before
run_event_loop returns, so an export call that triggered a collection also runs the cleanups
it queued. Happy to open a PR with it.

Lenguaje dominante
C
Estrellas
293
Forks
61
Merge medio
1 d 6 h
PR fusionados (30 d)
12

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de bytecodealliance/StarlingMonkey

Todos los issues de bytecodealliance/StarlingMonkey

Issues similares

Más issues de C

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.