[JsRuntimeHost] No adapter implements napi_add_env_cleanup_hook, forcing per-environment native state to be process-global

Abierto
#2,046 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
25/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Tranquilo
Stack tecnológico
cpp, javascript
Área
backend

Línea de trabajo

Start with grep for napi_add_env_cleanup_hook under Core/Node-API/Source, which currently has no matches, then read Core/Node-API/Include/Shared/napi/napi-inl.h where Napi::Env::AddCleanupHook calls it. The adapters to change are js_native_api_chakra.cc, js_native_api_javascriptcore.cc, js_native_api_quickjs.cc and js_native_api_v8.cc. Done means the hook is implemented in each adapter and Polyfills/URL/Source/URL.cpp can scope its blob URL store per environment and clear it on teardown.

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

Descripción

Summary

There is no portable way to run native cleanup when a JS environment is torn down, because no Node-API adapter in Core/Node-API/Source implements napi_add_env_cleanup_hook:

$ grep -rn "napi_add_env_cleanup_hook" Core/Node-API/Source
(no matches)

The only reference anywhere in the repo is the vendored node-addon-api header Core/Node-API/Include/Shared/napi/napi-inl.h, which calls it from Napi::Env::AddCleanupHook. That call has no implementation behind it in js_native_api_chakra.cc, js_native_api_javascriptcore.cc, js_native_api_quickjs.cc or js_native_api_v8.cc.

Impact

Native polyfill state that logically belongs to an environment has to be made process-global instead, and then leaks for the life of the process.

The concrete case is the blob URL store added in BabylonJS/JsRuntimeHost#207 (Polyfills/URL/Source/URL.cpp). URL.createObjectURL registers an entry that is normally released by URL.revokeObjectURL. Entries that are never revoked should be released when the environment goes away -- that is what a browser does at unload. With no teardown hook the store must be process-global, so an embedder that creates and destroys environments over the process lifetime accumulates every un-revoked blob URL, and the buffers behind them, until the process exits.

Polyfills/URL/Include/Babylon/Polyfills/URL.h documents the store as process-global for exactly this reason, and RegisterObjectURL/RevokeObjectURL already take a Napi::Env that is currently unused, kept for future per-env scoping.

Suggested fix

Implement napi_add_env_cleanup_hook and napi_remove_env_cleanup_hook in the adapters, then scope the blob URL store per environment and drop its entries from the cleanup hook.

Notes

Not covered by the existing issues: BabylonJS/JsRuntimeHost#194 was the JSC napi_typeof bug, BabylonJS/JsRuntimeHost#213 was the UrlLib blob: scheme resolver (implemented in BabylonJS/JsRuntimeHost#207), and BabylonJS/BabylonNative#2047 is the UrlLib Apple lifetime bug.

Lenguaje dominante
C++
Estrellas
931
Forks
169
Merge medio
2 d 17 h
PR fusionados (30 d)
66

Preparar el entorno

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 BabylonJS/BabylonNative

Todos los issues de BabylonJS/BabylonNative

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.