AbortSignal.any memory leak when circular dependencies
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- JavaScript
- Estrellas
- 122k
- Forks
- 37.3k
- Merge medio
- 4 d 2 h
- PR fusionados (30 d)
- 283
Descripción
Version
23.10.0
Platform
6.8.0-55-generic #57-Ubuntu SMP PREEMPT_DYNAMIC Wed Feb 12 23:42:21 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
No response
What steps will reproduce the bug?
class Test {
private abortController = new AbortController()
public test(cb: (abortSignal: AbortSignal) => void, abortSignal: AbortSignal) {
const signal = AbortSignal.any([abortSignal, this.abortController.signal])
cb(signal)
}
}
const registry = new FinalizationRegistry((heldValue) => {
console.log(`${heldValue} has been collected`)
})
;(() => {
const test = new Test()
registry.register(test, 'test')
const abortController = new AbortController()
test.test((abortSignal) => {
abortSignal.addEventListener('abort', () => {
console.log(test)
})
}, abortController.signal)
})()
global.gc?.()
setTimeout(() => {
console.log('the end')
}, 2000)
run with node --expose-gc test.ts
How often does it reproduce? Is there a required condition?
Every time
What is the expected behavior? Why is that the expected behavior?
the output should be
test has been collected
the end
because the test object is not referenced anymore
What do you see instead?
output:
the end
the test object is not garbage collected
Additional information
The issues seems to be caused by the cyclic dependency: test object => abortController field => abortSignal => AbortSignal.any result => cb function => test object
AbortSignal.any seems to prevent node from garbage collecting them all at once
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Ejecuta la reproducción proporcionada con node --expose-gc e inspecciona la interacción entre AbortSignal.any, AbortController y FinalizationRegistry descrita en la issue. La tarea está completada cuando el objeto de prueba haya sido recolectado y la salida incluya tanto “test has been collected” como “the end”.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript
- Área
- backend
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Activo
- Claridad
- Bastante claro
- Aptitud para principiantes
- 48/100