isImplementedInClass leaks the losing sample instance on re-entrant or racing cache population
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 38/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- cpp, objective-c
- Lĩnh vực
- mobile-dev
Hướng nghiên cứu
Bắt đầu trong NativeScript/runtime/Metadata.mm tại MethodMeta::isImplementedInClass và phần chú thích trỏ đến issue này; theo dõi việc tạo sampleInstances, cách sử dụng mutex và hành vi re-entrant của alloc. Hoàn thành nghĩa là loại bỏ các sample instances bị bỏ lại trong quá trình tạo re-entrant hoặc tạo có cạnh tranh mà không gây deadlock, giải phóng không an toàn hoặc giữ lại vĩnh viễn một cách có chủ đích.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Problem
MethodMeta::isImplementedInClass (NativeScript/runtime/Metadata.mm) keeps a process-wide cache of [klass alloc]-created sample instances used to answer respondsToSelector: for classes whose alloc returns a different class or which forward messages. The cache is populated like this:
[klass alloc]runs outside the mutex — deliberately, becausealloccan trigger+initialize, which may run arbitrary code that re-enters this method (holding the lock would deadlock).- The lock is then taken and
sampleInstances.emplace(klass, instance)inserts.
When the emplace loses — the re-entrant call already populated the entry for the same class, or another thread raced — the freshly allocated instance is abandoned: one leaked object per lost race (Instruments shows these as e.g. a leaked UIAlertView / NSURLSessionConfiguration attributed to isImplementedInClass). The count varies run to run since it is timing-dependent.
Why the obvious fixes don't work
- Releasing the loser is unsafe: the instance is
alloc'd but neverinit'd, so-releaseruns-deallocagainst zero-filled ivars of an arbitrary framework class, on whatever thread the probe ran on (it demonstrably runs on worker threads). Benign for most classes, but a-deallocthat doesCFRelease/dispatch_releaseon a zero ivar traps, and UIKit teardown off the main thread is asserting territory. - Holding the lock across
allocdeadlocks via the+initializere-entry described above. - Parking losers in a static container merely converts the unreachable leak into intentional perpetual retention — it silences Instruments without reclaiming anything (tried and reverted in #458).
Potential solutions
- A re-entrancy-aware locking scheme (recursive mutex, or a reader/writer arrangement) so the populate path can be made atomic with respect to re-entrant probes without deadlocking through
+initialize. - Reuse already-
alloc-ed objects: when a sample for that Class is requested (or something else calls[thatClass alloc]through the runtime), hand out / consume the cached instance instead of allocating another, so a losing instance gets used rather than abandoned.
The leak site carries a comment pointing at this issue.
- Ngôn ngữ chính
- JavaScript
- Star
- 150
- Fork
- 43
- Merge trung bình
- 3 ngày 10 giờ
- Pull request đã merge (30 ngày)
- 22
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 NativeScript/ios
-
worker.terminate() is a no-op during entry evaluation, and terminating there wedges teardown Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
NativeScript/ios#445 ·
-
Độ khó 3/5 3-5 ngày Mức phù hợp với người mới 66/100
NativeScript/ios#414 ·
-
question
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 34/100
NativeScript/ios#364 · 2 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
NativeScript/ios#355 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
NativeScript/ios#292 · 9 bình luận ·
Tất cả issue của NativeScript/ios
Issue tương tự
-
code-quality refactoring
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
langchain-ai/deepagents#6450 ·
-
optimization optimization:agents-md-curator
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
githubnext/gh-aw-cao#13143 ·
-
status: needs triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100