[Bug]: Android Bridge.savedCalls / savedPermissionCallIds are HashMaps accessed from several threads without synchronization
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 48/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- TypeScript
- Stelle
- 17.1k
- Fork
- 1.3k
- Merge medio
- 1g 22h
- PR unite (30g)
- 26
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di ionic-team/capacitor
-
triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
ionic-team/capacitor#8759 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: Plugin call after navigation can be answered before reply proxy is updatedForse già presa @MateStrysewske l’ha presa 71 giorni fa. Apertatriage
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
ionic-team/capacitor#8616 ·
I maintainer di solito rispondono entro 1 giorno
-
help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
ionic-team/capacitor#8574 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
SystemBars: safe area CSS injection throws "Cannot read properties of null" on startup (Android 16)Forse già presa @kttalley l’ha presa 62 giorni fa. Apertatriage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
ionic-team/capacitor#8530 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
fix(android): remove unchecked Java compilation warningsForse già presa @Ajamuar l’ha presa 15 giorni fa. Apertatriage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
ionic-team/capacitor#8529 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di ionic-team/capacitor
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
prio:low scope:world
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
OliverRomhagen/vrigstad-joyride#849 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
genfeedai/genfeed.ai#11916 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
erkamyaman/rust-anything#1153 ·
I maintainer di solito rispondono entro 1 giorno
-
The Phase 5 report says 0.3.0 waits for the live checkForse già presa @fzn0x l’ha presa oggi. Apertadocumentation
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno