[Bug]: Android Bridge.savedCalls / savedPermissionCallIds are HashMaps accessed from several threads without synchronization
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 48/100
調査の方向性
Start with android/capacitor/src/main/java/com/getcapacitor/Bridge.java and trace the listed access points: saveCall, getSavedCall, releaseCall, getPermissionCall, savePermissionCall, and reset(). Check how the permission callback reaches these methods in Plugin.java, MessageHandler.java, and PluginCall.java; the issue suggests guarding shared state or using a concurrent map while protecting the permission ID lists. Done means both call storage and permission ID access are safe across the named threads.
索引モデルが issue の本文から書いたものです。
説明
Capacitor Version
@capacitor/android: 8.6.0
@capacitor/core: 8.6.0
Also checked: android/capacitor/src/main/java/com/getcapacitor/Bridge.java on main (2026-11-17), same code.
Other API Details
N/A - all versions
Platforms Affected
- iOS
- Android
- Web
Current Behavior
Bridge.savedCalls (Bridge.java:151) and Bridge.savedPermissionCallIds (:154) are plain
HashMaps, and the savedCalls field is neither final nor volatile. They are read and written
from more than one thread with no lock:
| Thread | Access |
|---|---|
CapacitorPlugins handler thread (taskHandler) |
saveCall after a kept-alive call returns (callPluginMethod, Bridge.java:849-851; e.g. every addListener); savePermissionCall (:990-997, from Plugin.requestPermissionForAliases); getSavedCall + releaseCall in Plugin.removeListener (Plugin.java:748-756) |
| main thread | reset() replaces savedCalls (Bridge.java:576-577, called from BridgeWebViewClient.onPageStarted); the permission result callback Plugin.triggerPermissionCallback (Plugin.java:133-134) runs getPermissionCall (polls the LinkedList in savedPermissionCallIds, then reads savedCalls), and the call it resolves is then removed by PluginCall.release -> Bridge.releaseCall (MessageHandler.java:136-138, PluginCall.java:360-362) |
| any thread a plugin resolves on | releaseCall via MessageHandler.sendResponseMessage for every call that is not kept alive |
Most of the off-thread releaseCalls remove a key that was never saved (calls that are not kept
alive are not put in the map), so they only read the map. The pair that writes concurrently is:
- The main thread removes a saved permission call after the permission result is delivered
(HashMap.removeof a present key), while - the
CapacitorPluginsthread runssaveCallfor another call, e.g. anaddListenerfrom the
page (HashMap.put, possibly resizing).
savedPermissionCallIds has the same shape: put/add on the plugin thread, poll on the main
thread.
The likely effect of the race is a lost entry: a later removeListener then gets null from getSavedCall and leaves the listener call in the plugin's eventListeners, or a released call stays in savedCalls.
Expected Behavior
savedCalls and savedPermissionCallIds are safe to access from the threads that Capacitor
itself uses for them (the plugin handler thread and the main thread), and from the thread a plugin
resolves on.
Possible change:
- Guard
saveCall,getSavedCall,releaseCall,getPermissionCall,savePermissionCalland
the map replacement inreset()with one lock (e.g.synchronizedon a private final object),
or - use
ConcurrentHashMapforsavedCalls, make the fieldfinaland havereset()call
clear()instead of assigning a new map.ConcurrentHashMaprejectsnullkeys, so
saveCall/releaseCallwould need a null check oncallbackId;savedPermissionCallIds
holdsLinkedLists that are mutated in place, so it would still need a lock.
Project Reproduction
N/A - any multi-threaded project on Android could potentially encounter this
Additional Information
On iOS, CapacitorBridge.storedCalls is a ConcurrentDictionary and its reset uses
withLock, so the Android side appears to be the only one affected. The permission result
callback runs on the main thread because AndroidX delivers ActivityResultCallbacks there.
- 主要言語
- TypeScript
- スター
- 17.1k
- フォーク
- 1.3k
- 平均マージ
- 1日 22時間
- マージ済み PR(30日)
- 26
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ionic-team/capacitor のほかの issue
-
triage
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
ionic-team/capacitor#8759 ·
メンテナーはふだん 1 日以内に返信
-
[Bug]: Plugin call after navigation can be answered before reply proxy is updated対応中かも @MateStrysewske が 71 日前に担当しました。 オープンtriage
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
ionic-team/capacitor#8616 ·
メンテナーはふだん 1 日以内に返信
-
help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
ionic-team/capacitor#8574 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
SystemBars: safe area CSS injection throws "Cannot read properties of null" on startup (Android 16)対応中かも @kttalley が 62 日前に担当しました。 オープンtriage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
ionic-team/capacitor#8530 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
fix(android): remove unchecked Java compilation warnings対応中かも @Ajamuar が 15 日前に担当しました。 オープンtriage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
ionic-team/capacitor#8529 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
ionic-team/capacitor の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
prio:low scope:world
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
OliverRomhagen/vrigstad-joyride#849 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
genfeedai/genfeed.ai#11916 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
erkamyaman/rust-anything#1153 ·
メンテナーはふだん 1 日以内に返信
-
The Phase 5 report says 0.3.0 waits for the live check対応中かも @fzn0x が今日担当しました。 オープンdocumentation
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信