WasmFS: ProxyWorker's 50 ms heartbeat outlives its thread and runs the freed queue on a pooled Worker (`Assertion failed: pthread_self()` in `emscripten_proxy_execute_queue`)
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 35/100
Línea de trabajo
Start with the heartbeat in src/lib/libwasmfs.js and ProxyWorker lifecycle in system/lib/wasmfs/thread_utils.h, then review Worker pooling in src/lib/libpthread.js. Run the provided proxy_worker_exit.cpp command with -pthread, -sWASMFS, -sPTHREAD_POOL_SIZE=2, and -sEXIT_RUNTIME; done means repeated heartbeats no longer access the destroyed queue or abort after worker reuse.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
emscripten::ProxyWorker (system/lib/wasmfs/thread_utils.h), which the OPFS and fetch backends use for their dedicated thread, starts a heartbeat on that thread: a 50 ms setInterval that calls emscripten_proxy_execute_queue() on the ProxyWorker's queue. Nothing stops it except ABORT.
~ProxyWorker() cancels and joins the thread, and then the queue is freed. But the thread's Worker goes back to the pool rather than being terminated, and its timer goes with it. So every 50 ms the Worker runs a freed queue: while it is idle, pthread_self() is null and, with assertions, emscripten_proxy_execute_queue() aborts; without assertions, or once the Worker hosts another thread, it reads freed memory. Backends are destroyed at exit with EXIT_RUNTIME, so a program with an OPFS or fetch backend can abort at exit this way.
Version of emscripten/emsdk:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 6.0.12-git (ce6d2aad8bbf1e508e5a6d112f986617198bdc0d)
clang version 24.0.0git (https:/github.com/llvm/llvm-project d3e9891b54da54deebe2a6df0eb67c8ec155fa65)
main at ce6d2aad8 with the toolchain from test/emsdk_version.txt (dbaebb43), Node.js v24.19.0, x86_64 Linux.
Test case (proxy_worker_exit.cpp, which includes the internal header as a backend does):
// A destroyed ProxyWorker must leave nothing running against its freed queue,
// both while its Worker is idle in the pool and once it hosts another thread.
// Each wait spans several of the thread's 50 ms heartbeats.
#include <assert.h>
#include <condition_variable>
#include <emscripten/emscripten.h>
#include <emscripten/eventloop.h>
#include <mutex>
#include <stdio.h>
#include <thread>
#include "thread_utils.h"
// A ProxyWorker can't be created on the main browser thread.
static void use_worker() {
std::thread([] {
emscripten::ProxyWorker worker;
bool ran = false;
worker([&] { ran = true; });
assert(ran);
}).join();
}
static void second_idle(void*) {
printf("done\n");
emscripten_force_exit(0);
}
static void first_idle(void*) {
use_worker();
emscripten_set_timeout(second_idle, 500, nullptr);
}
int main() {
use_worker();
emscripten_set_timeout(first_idle, 500, nullptr);
}
Failing command line in full:
$ em++ -pthread -sWASMFS -sPTHREAD_POOL_SIZE=2 -sEXIT_RUNTIME -I$EMSCRIPTEN/system/lib/wasmfs proxy_worker_exit.cpp -o t.js
$ node t.js
Aborted(Assertion failed: pthread_self(), at: /emsdk/emscripten/system/lib/pthread/proxying.c,113,emscripten_proxy_execute_queue)
worker sent an error! undefined:undefined: Aborted(Assertion failed: pthread_self(), at: /emsdk/emscripten/system/lib/pthread/proxying.c,113,emscripten_proxy_execute_queue)
node:internal/event_target:1136
process.nextTick(() => { throw err; });
^
RuntimeError: Aborted(Assertion failed: pthread_self(), at: /emsdk/emscripten/system/lib/pthread/proxying.c,113,emscripten_proxy_execute_queue)
at abort (t.js:855:11)
at ___assert_fail (t.js:1743:7)
at wasm://wasm/0006d26e:wasm-function[189]:0x3aa3
at t.js:887:12
at Timeout._onTimeout (t.js:2262:13)
at listOnTimeout (node:internal/timers:635:17)
at process.processTimers (node:internal/timers:571:7)
Node.js v24.19.0
[exit status 1]
It aborts in 10 runs out of 10. At -O2 (no assertions) it prints done, since the freed queue is still readable and empty.
Where:
- The heartbeat (libwasmfs.js#L581-L591), started on the worker thread (thread_utils.h#L64).
- The destructor cancels and joins the thread; the
queuemember is destroyed after it (thread_utils.h#L91-L94). - The exiting thread clears
pthread_self()(pthread_create.c#L370), and its Worker goes back to the pool, not terminated (libpthread.js#L224-L236). - The next tick fails here (proxying.c#L113).
I have a fix ready and will send a PR: the destructor stops the heartbeat on the thread, with a synchronous proxied call, before cancelling it.
- Lenguaje dominante
- C++
- Estrellas
- 27.8k
- Forks
- 3.6k
- Merge medio
- 1 d 3 h
- PR fusionados (30 d)
- 179
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la 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.
Más de emscripten-core/emscripten
-
`other.test_cmake_cxx_import_std` fails on CMake 3.30–4.0.2 due to missing `CMAKE_EXPERIMENTAL_CXX_IMPORT_STD` UUIDsPosiblemente ocupada @subhaushsingh la tomó hace 1 día. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
emscripten-core/emscripten#28160 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
emscripten-core/emscripten#27994 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
LEGACY_GL_EMULATION: generated fixed-function fragment shaders use mediump — fp16 overflow where mediump is half precisionPosiblemente ocupada @TheTomBritton la tomó hace 12 días. AbiertoDesktop OpenGL emulation
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
emscripten-core/emscripten#27948 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
emscripten-core/emscripten#27906 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
run_python, run_python_compiler could readlink -fPosiblemente ocupada @kapouer la tomó hace 128 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
emscripten-core/emscripten#27211 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de emscripten-core/emscripten
Issues similares
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 65/100
-
[XLA] hlo/pass/README.md says passes implement Run; since the NVI change they implement RunImplAbierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 91/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
NVIDIA-RTX/NRI#312 ·
Los mantenedores suelen responder en 1 día
-
permute_q_b_proj / permute_wv_proj accept scale factors from another devicePosiblemente ocupada @0z5a la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
deepseek-ai/FlashMLA#247 ·
Los mantenedores suelen responder en 1 día
-
Linux npm packaging leaves workspace files that block subsequent CI checkoutPosiblemente ocupada @Spockkk0225 la tomó hoy. Abiertoci
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
alibaba/neug#1195 · 1 comentario ·
Los mantenedores suelen responder en 1 día