Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Android: per-runtime statics are read and written from runtime threads without a lock

未关闭
#99 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
android, cpp
领域
backend, mobile

调研方向

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 内容生成。

描述

bug

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::ConcurrentMap with the Get / Insert / Remove pattern used in #96, or become per-runtime state;
  • APP_ROOT_FOLDER_PATH is set once per process, since every runtime computes the same value (filesRoot + "/app/"), or is guarded.

Environment

  • Branch: android-react-native at 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 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

NativeScript/runtimes 的其他 Issue

查看 NativeScript/runtimes 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。