[Bug]: Android Bridge.savedCalls / savedPermissionCallIds are HashMaps accessed from several threads without synchronization
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 48/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- TypeScript
- Star
- 17.1k
- Fork
- 1.3k
- Merge trung bình
- 1 ngày 22 giờ
- Pull request đã merge (30 ngày)
- 26
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của ionic-team/capacitor
-
triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
ionic-team/capacitor#8759 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: Plugin call after navigation can be answered before reply proxy is updatedCó thể đã có người làm @MateStrysewske đã nhận 71 ngày trước. Đang mởtriage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
ionic-team/capacitor#8616 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
ionic-team/capacitor#8574 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
SystemBars: safe area CSS injection throws "Cannot read properties of null" on startup (Android 16)Có thể đã có người làm @kttalley đã nhận 62 ngày trước. Đang mởtriage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
ionic-team/capacitor#8530 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
fix(android): remove unchecked Java compilation warningsCó thể đã có người làm @Ajamuar đã nhận 15 ngày trước. Đang mởtriage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
ionic-team/capacitor#8529 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của ionic-team/capacitor
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
prio:low scope:world
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
OliverRomhagen/vrigstad-joyride#849 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
genfeedai/genfeed.ai#11916 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
erkamyaman/rust-anything#1153 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
The Phase 5 report says 0.3.0 waits for the live checkCó thể đã có người làm @fzn0x đã nhận hôm nay. Đang mởdocumentation
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày