[iOS] Crash at app exit: static `_managers` map destroyed while `flushOperations` reads it
Maintainer thường phản hồi trong vòng 2 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 30/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- cpp, objective-c
- Lĩnh vực
- mobile
Hướng nghiên cứu
The declaration and the readers are all in packages/react-native-gesture-handler/apple/RNGestureHandlerModule.mm: start at the namespace-scope _managers map, then read flushOperations (around line 185) and +handlerManagerForModuleId: to see the exit-time race. Note that PR #4712 already carries the construct-on-first-use fix, so check that thread before writing anything; the standalone reproducer in the linked Gist is the quickest way to see the mechanism. Done means the map is never destroyed at exit and the Gist model no longer trips ThreadSanitizer or crashes.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
[!NOTE]
This issue was authored by AI on behalf of @beqramo.
The iOS app sometimes crashes while it is quitting. _managers in RNGestureHandlerModule.mm is a namespace-scope static:
static std::unordered_map<int, RNGestureHandlerManager *> _managers;
Its destructor is registered with __cxa_atexit. When the app quits through exit() (for example -[NSApplication terminate:] when the iOS app runs on an Apple Silicon Mac), the main thread destroys the map in __cxa_finalize. At the same moment the mounting queue can still be in flushOperations -> +handlerManagerForModuleId: -> _managers.find(...), which reads the destroyed hash table and crashes (EXC_BAD_ACCESS / SIGSEGV).
Crashed thread (mounting queue), symbolicated frames:
std::__1::__hash_table<std::__1::__hash_value_type<int, RNGestureHandlerManager*>, ...>::find<int>
+[RNGestureHandlerModule handlerManagerForModuleId:]
-[RNGestureHandlerModule flushOperations] RNGestureHandlerModule.mm:185
Main thread at the same moment:
std::__1::__hash_table<std::__1::__hash_value_type<int, RNGestureHandlerManager*>, ...>::~__hash_table
__cxa_finalize
exit
-[NSApplication terminate:]
The crash reports say the app was not in the foreground, so users see it as "the app crashed when I quit it".
Expected: quitting the app never crashes, even if a flushOperations is still running on the mounting queue.
Proposed fix (PR #4712): allocate the map once and never destroy it (construct-on-first-use idiom). Nothing changes while the app runs; the OS reclaims the memory at exit.
-static std::unordered_map<int, RNGestureHandlerManager *> _managers;
+static auto &_managers = *new std::unordered_map<int, RNGestureHandlerManager *>();
The same declaration is still on main (packages/react-native-gesture-handler/apple/RNGestureHandlerModule.mm).
Versions of related libraries installed in the app:
- react-native-reanimated 4.7.1
- react-native-worklets 0.13.0
- react-native-screens 4.30.0
- Expo SDK 58 (prebuild)
Steps to reproduce
This is a race between process exit and the mounting queue, so there is no deterministic app-level reproducer. In the app:
- Build an app with react-native 0.88.0 (New Architecture) and react-native-gesture-handler 3.3.0 in release mode, with gesture handlers on screen (so
flushOperationsruns on the mounting queue). - Run the iOS build on an Apple Silicon Mac ("Designed for iPad").
- While the UI is updating (an animation or a list re-rendering), quit the app (Cmd+Q).
-[NSApplication terminate:]callsexit(). - Sometimes the process crashes during quit with the two stacks above.
To see the mechanism deterministically, use the standalone C++ model in the Gist below (a static std::unordered_map read by another thread while main returns):
- Download
static_map_exit_race.cppfrom the Gist. clang++ -std=c++17 -g -O2 static_map_exit_race.cpp -o plain && ./plain; echo "exit=$?"-> crashes with SIGSEGV (exit 139). It crashed in 50 of 50 runs on Apple clang 21, macOS 26.2, Apple Silicon.clang++ -std=c++17 -g -O1 -fsanitize=thread static_map_exit_race.cpp -o tsan_plain && ./tsan_plain-> ThreadSanitizer reports a data race between~unordered_map(main thread, from__cxa_atexit) and the reader thread.- Rebuild with
-DLEAKY(the proposed fix) -> 0 of 50 runs crashed, and there is no ThreadSanitizer or AddressSanitizer report.
A link to a Gist, an Expo Snack or a link to a repository based on this template that reproduces the bug.
https://gist.github.com/beqramo/faafb2c113671472e8c46eeda211984c
Gesture Handler version
3.3.0
React Native version
0.88.0
Platforms
iOS
JavaScript runtime
Hermes
Workflow
Using Expo Prebuild or an Expo development build
Build type
Release mode
Device
Real device
Device model
The iOS app ("Designed for iPad") running on Apple Silicon Macs, at quit
Acknowledgements
Yes
- Ngôn ngữ chính
- TypeScript
- Star
- 6.8k
- Fork
- 1.1k
- Merge trung bình
- 2 ngày 17 giờ
- Pull request đã merge (30 ngày)
- 28
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Không 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 software-mansion/react-native-gesture-handler
-
GestureDetector should bubble touches if all gestures fail (or some other generalized solution)Đang mởMissing repro Platform: Android Platform: iOS
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 39/100
software-mansion/react-native-gesture-handler#4714 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[Web] A pan that starts on a Pressable presses it when the mouse button is releasedCó thể đã có người làm @mokshupadhyay đã nhận 1 ngày trước. Đang mởPlatform: Web
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 57/100
software-mansion/react-native-gesture-handler#4713 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[iOS][Fabric] Recognizer of a live handler stays on a recycled view and takes every drag on the component that reuses itCó thể đã có người làm @nihar777 đã nhận 5 ngày trước. Đang mởPlatform: iOS
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
software-mansion/react-native-gesture-handler#4710 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[iOS] Button press feedback invisible on quick taps when Reduce Motion is enabledCó thể đã có người làm @andreialecu đã nhận 7 ngày trước. Đang mởMissing info Platform: iOS Platform: MacOS
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
software-mansion/react-native-gesture-handler#4707 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Missing info Platform: Android
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 22/100
software-mansion/react-native-gesture-handler#4706 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của software-mansion/react-native-gesture-handler
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
ehmpathy/rhachet-roles-bhrain#878 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Chat UI: Message actions dropdown is cut off beneath composer when message is near bottom of chatCó thể đã có người làm @koeria đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
milind-soni/OpenMausBot#8023 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Windows microphone listing treats words in a device name as DirectShow labelsCó thể đã có người làm @Sujal-chaudhary đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
clipy-recorder/clipy#447 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement from-app needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
nightly-labs/openbot#19162 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
triage:in-progress
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Cotal-AI/Cotal#11229 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày