Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン
#99 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
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分
マージ済み PR(30日)
4

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

NativeScript/runtimes のほかの issue

NativeScript/runtimes の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。