Android: data race on ArgConverter's process-wide long-conversion cache when workers start or stop concurrently
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- C++
- Star
- 27
- Fork
- 4
- Merge trung bình
- 16 giờ 48 phút
- Pull request đã merge (30 ngày)
- 4
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của NativeScript/runtimes
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
NativeScript/runtimes#100 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
NativeScript/runtimes#99 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 4/5 1-2 ngày Mức phù hợp với người mới 55/100
NativeScript/runtimes#98 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 53/100
NativeScript/runtimes#97 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
NativeScript/runtimes#94 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của NativeScript/runtimes
Issue tương tự
-
good first issue invalid
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
DanielJerolm/gpcc#74 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
patrick-hudson/put.gd-desktop#808 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
DPI change is not fully handled in the cascading window on WindowsCó thể đã có người làm @yukawa đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 4 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement Ready for final check
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
mpogue2/SquareDesk#1818 · 1 bình luận ·