Android: data race on ArgConverter's process-wide long-conversion cache when workers start or stop concurrently
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
Direzione di ricerca
Read NativeScript/ffi/jni/napi/conversion/ArgConverter.{h,cpp} and NativeScript/ffi/jni/jsi/conversion/ArgConverter.{h,cpp}, focusing on GetTypeLongCache() and the disposal paths onDisposeEnv() and onDisposeRuntime(). Reproduce the reported race with the worker stress test on an API 36 arm64 emulator using HWASan; the issue describes enabling it in platforms/android/test-app/runtime/CMakeLists.txt. Done means concurrent runtime creation and disposal no longer corrupts either cache.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
ArgConverter::s_type_long_operations_cache is a single, process-wide robin_hood::unordered_map. Each runtime finds, inserts and erases its own entry from its own thread, and nothing synchronizes those accesses:
- find / insert:
GetTypeLongCache(), on the firstlongconversion in that runtime. - erase:
onDisposeEnv()/onDisposeRuntime(), when the runtime is disposed.
When several workers start or stop at once, one thread can rehash the table while another is reading or writing it. That is a data race on the map, and in practice a heap use-after-free.
Affects both binding layers:
NativeScript/ffi/jni/napi/conversion/ArgConverter.{h,cpp}: the map is keyed bynapi_env.NativeScript/ffi/jni/jsi/conversion/ArgConverter.{h,cpp}: the map is keyed byrt.identity().
How it was found
A worker stress test, run while testing #91 and #92 on an API 36 arm64 emulator. HWASan was enabled locally by uncommenting the -fsanitize=hwaddress lines in platforms/android/test-app/runtime/CMakeLists.txt; it is off by default. The test:
- 12 workers at a time are created and terminated after 20–300 ms;
- each worker churns Java objects and forces JS and Java GC;
- the main runtime forces GC every 25 ms.
HWASan reported a memory error inside ArgConverter::GetTypeLongCache, in both the napi and jsi trees. On the old code (without #91), the crash happened in 1 of 3 napi runs and 1 of 2 jsi runs. It is independent of the GC-delivery race that #91 fixes.
Expected
Each runtime's cache is reachable only by that runtime, and creating or disposing one runtime can't corrupt another's entry. Possible fixes:
- make the cache per-runtime state, reached the way
MetadataNode's per-runtime cache is; - or guard the map with a mutex. This is cheap: a lookup happens once per
longconversion, and the pointer could be cached after that.
Environment
- Branch:
android-react-nativeat 64c7fed0 - Emulator: Android API 36, arm64, debug build of
platforms/android/test-appwith HWASan enabled locally - Engine: V8
- Lingua principale
- C++
- Stelle
- 27
- Fork
- 4
- Merge medio
- 16h 48m
- PR unite (30g)
- 4
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di NativeScript/runtimes
-
bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
NativeScript/runtimes#100 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
NativeScript/runtimes#99 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 4/5 1-2 giorni Idoneità per principianti 55/100
NativeScript/runtimes#98 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 53/100
NativeScript/runtimes#97 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
NativeScript/runtimes#94 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di NativeScript/runtimes
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
godotengine/godot#125004 ·
I maintainer di solito rispondono entro 1 giorno
-
44-x-y bug :beetle:
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
electron/electron#55528 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
gabime/spdlog#3698 · 1 commento ·
I maintainer di solito rispondono entro 5 giorni
-
ai_p2 bug comp-datalake
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
ClickHouse/ClickHouse#128306 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
70 Instance - Raid - Outland
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
azerothcore/azerothcore-wotlk#28328 ·
I maintainer di solito rispondono entro 1 giorno