0xMiden / 0xMiden/web-sdk

WebClient.terminate() releases nothing for an in-realm client (useWorker=false): wasm object never freed, IndexedDB connection never closed

Abierto
#377 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
TypeScript
Estrellas
1
Forks
21
Merge medio
12 h 14 min
PR fusionados (30 d)
41

Descripción

A `WebClient` created with `useWorker=false` cannot be released: `terminate()` only sets a flag and forwards to the worker shim, whose `terminate()` is `if (this.worker) this.worker.terminate()`, so with no worker nothing happens. The wasm-bindgen client is left to the FinalizationRegistry and the Dexie store it opened is never closed. A caller that builds a short-lived client per read, which is the documented way to get a second client object past the single-threaded aliasing guard, leaks one open `IDBDatabase` per call.

**Measured** (wallet extension, 0.16.0, offscreen document, one such client every 30 s, counts after a forced GC): `IDBDatabase` objects 6 → 8 → 10 → 12 over four minutes and still climbing after 55 h, where the renderer died of a V8 OOM (0xMiden/wallet#868).

- `dist/mt/index.js`: `terminate() { this.#terminated = true; this.#inner.terminate?.(); }` and the shim's `terminate() { if (this.worker) this.worker.terminate(); }`.
- Store glue (`dist/mt/Cargo-*.js`): `openDatabase` does `databaseRegistry.set(network, db)`, replacing the previous entry for the same network without closing it; the only `dexie.close()` is on the client-version-mismatch reset.

**Expected.** `terminate()` (and `Symbol.dispose`) on an in-realm client frees the wasm object and closes its store, and `openDatabase` closes the entry it replaces (or reuses it).

**Reviewers:** the two one-line functions above are the whole report.

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Look at `dist/mt/index.js` for the `terminate()` method and the worker shim's `terminate()`. Examine `dist/mt/Cargo-*.js` for `openDatabase` and the `databaseRegistry`. The fix involves ensuring `terminate()` properly cleans up the wasm object and closes the IndexedDB connection when `useWorker=false`. Test by creating a short-lived client and checking that no `IDBDatabase` objects leak after GC.

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

Evaluación

Stack tecnológico
javascript, typescript, wasm
Área
databases, tooling, web-dev
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Activo
Claridad
Bien especificado
Aptitud para principiantes
65/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.