Android: per-runtime statics are read and written from runtime threads without a lock
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start by reading the listed Android N-API and JSI files, then compare their shared static maps and APP_ROOT_FOLDER_PATH assignments with the tns::ConcurrentMap usage mentioned in the issue and the Hermes env_to_jsr_mutex guard. Check how the quickjs and primjs backends store env_to_jsr_cache as well. Done means concurrent runtime creation and disposal cannot corrupt state another runtime reads; the issue names no tests to run.
由索引模型根据 Issue 内容生成。
描述
Summary
Several process-wide statics hold one entry per runtime, or one value set by every runtime. Each runtime reads and writes them from its own thread, with no lock. When workers start or stop while other runtimes are running, these are data races of the same kind as #93: a hash table can rehash under a concurrent reader, and a std::string can be reallocated under a concurrent reader.
| Static | Where | Written | Read |
|---|---|---|---|
JSR::env_to_jsr_cache (std::unordered_map) |
NativeScript/napi/v8/jsr.cpp |
js_create_napi_env, js_free_napi_env |
js_lock_env / js_unlock_env |
MetadataNode::s_arrayObjects (robin_hood::unordered_map) |
NativeScript/ffi/jni/{napi,jsi}/metadata/MetadataNode.cpp |
first array-constructor lookup in each runtime; erased on dispose | every array-constructor lookup |
envToPersistentSmartJSONStringify / rtToPersistentSmartJSONStringify (robin_hood::unordered_map) |
NativeScript/ffi/jni/{napi,jsi}/global/GlobalHelpers.cpp |
first JsonStringifyObject in each runtime; erased on dispose |
every JsonStringifyObject |
Constants::APP_ROOT_FOLDER_PATH (std::string) |
NativeScript/ffi/jni/{napi,jsi}/constants/Constants.cpp |
assigned in Runtime::Init of every runtime (NativeScript/runtime/android/{napi,jsi}/Runtime.cpp) |
module resolution, stack traces, MetadataNode origins, inspector |
The quickjs and primjs backends keep env_to_jsr_cache in a tns::SimpleMap, which has no lock either. The hermes backend already guards its copy with env_to_jsr_mutex.
MetadataNode::s_metadata_node_cache and (with #96) ArgConverter's long-conversion cache already use tns::ConcurrentMap, which is the pattern to follow for the maps.
Expected
Creating or disposing one runtime can't corrupt state another runtime is reading. Possible fixes:
- the per-runtime maps move to
tns::ConcurrentMapwith theGet/Insert/Removepattern used in #96, or become per-runtime state; APP_ROOT_FOLDER_PATHis set once per process, since every runtime computes the same value (filesRoot + "/app/"), or is guarded.
Environment
- Branch:
android-react-nativeat 64c7fed0 - Found by reading the code while fixing #93; these were not seen crashing on their own.
Related: #93, #96, and #97 and #98 (the console timer maps).
- 主要语言
- C++
- 星标
- 27
- 派生
- 4
- 平均合并
- 16 小时 48 分钟
- 30 天内合并 PR
- 4
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
NativeScript/runtimes 的其他 Issue
-
bug
难度 4/5 3-5 天 新手友好度 48/100
NativeScript/runtimes#100 ·
维护者通常 1 天内回复
-
bug
难度 4/5 1-2 天 新手友好度 55/100
NativeScript/runtimes#98 ·
维护者通常 1 天内回复
-
bug
难度 4/5 3-5 天 新手友好度 53/100
NativeScript/runtimes#97 · 1 条评论 ·
维护者通常 1 天内回复
-
bug
难度 4/5 3-5 天 新手友好度 48/100
NativeScript/runtimes#94 ·
维护者通常 1 天内回复
-
bug
难度 4/5 3-5 天 新手友好度 48/100
NativeScript/runtimes#93 ·
维护者通常 1 天内回复
查看 NativeScript/runtimes 的全部 Issue
相似的 Issue
-
bug-unconfirmed
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 1 天内回复
-
Extended search mode does not find escape sequences (\t, \n, \r...)可能已有人在做 @CyrilB1531 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 87/100
dail8859/NotepadNext#1181 ·
维护者通常 1 天内回复
-
A-tools P-low S-blocked task
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
☢️ Bug
难度 2/5 1-3 小时 新手友好度 78/100
OpenAtomFoundation/pikiwidb#3309 ·
-
audit(c2): add_project_arguments('/experimental:c11atomics', language: ['c', 'cpp']) for MS (C2-13)未关闭hygiene type:refactor
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 1 天内回复