expo: [expo-keep-awake][ios] Constant crashes / EXC_BAD_ACCESS / NSInvalidArgumentException
Summary
expo-keep-awake is flooding my Sentry crash reports. Of course, I can’t reproduce it, I don’t know why it happens but I have a single use of expo-keep-awake, which I tried to replicate in a Snack
expo-dev-client
Here are the two sentry crash logs:


The only thing I am doing is to call activateKeepAwake and deactivateKeepAwake on focus/blur.
Thats it. It did not crash for me but for my users. I think it happens when the app was backgrounded for a while and when the user returns.
Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!
bare
What platform(s) does this occur on?
iOS
SDK Version (managed workflow only)
45
Environment
expo-env-info 1.0.4 environment info:
System:
OS: macOS 12.4
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.15.1 - ~/.nvm/versions/node/v16.15.1/bin/node
Yarn: 3.2.0 - ~/.nvm/versions/node/v16.15.1/bin/yarn
npm: 8.11.0 - ~/.nvm/versions/node/v16.15.1/bin/npm
Watchman: 2022.02.14.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.11.2 - /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5
IDEs:
Android Studio: 2021.2 AI-212.5712.43.2112.8512546
Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild
npmGlobalPackages:
eas-cli: 0.54.1
expo-cli: 5.5.1
Expo Workflow: bare
Reproducible demo
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 2
- Comments: 40 (25 by maintainers)
As the @expo-bot said above, I’ve just published a potential fix for these crashes in version
10.2.1. Please keep in mind that we were not able to reproduce the issue and so we couldn’t test if it really fixes the issue. Volunteers are welcome 😄10.2.xversions are generally intended to be used with SDK46, but this one should also be compatible with SDK45.Even though I hope it solves the problem, I’m reopening it until I get a confirmation that it works and doesn’t cause any more crashes.
I’ll release an app update including the change this week. Might take 10 days for further feedback.
For now - until resolved - I would recommend using https://github.com/sayem314/react-native-keep-awake @trajano Works fine.
@timlangeSystl
No idea as I’m not core team but the workaround is to remove the keep awake functionality (if you can), or to switch to https://github.com/sayem314/react-native-keep-awake (which would require a custom dev client if you’re in managed).
Hey Andy and Bartłomiej! Our repo is open-source now so it might be really easy for you to reproduce. You can uncomment this code to reproduce the crash (happening at launch): https://github.com/showtime-xyz/showtime-frontend/commit/c46bfa85496e034fee3c89b4197feabf7f825c90. Let me know if you want to jump on a call to set up the app.
@tsapeta I can confirm once more, that I have never seen this issue again after your change. I think this issue is fixed.
@barthap Hah yes, but as always updating a big dependency like Expo can cause more problems than it fixes (as we see with the 45 bump here creating this issue for us), so we don’t really have the appetite for it right now - especially given it’s an unpredictable and intermittent bug which has very negative user implications.
Probably also worth noting that we only saw this after updating to expo 45 so my uninformed opinion is that it’s probably related to this https://github.com/expo/expo/commit/02b61e24659a7cc448c788b7930003e299e2a29b
The most cryptic part is that both stacktraces point to lines that are typical Swift Set operations: 1. https://github.com/expo/expo/blob/40c4a73859a5e1676a9a3fd502d25b2a378b521a/packages/expo-keep-awake/ios/KeepAwakeModule.swift#L28
https://github.com/expo/expo/blob/40c4a73859a5e1676a9a3fd502d25b2a378b521a/packages/expo-keep-awake/ios/KeepAwakeModule.swift#L31
The
activeTagsis just a normal module property: https://github.com/expo/expo/blob/40c4a73859a5e1676a9a3fd502d25b2a378b521a/packages/expo-keep-awake/ios/KeepAwakeModule.swift#L5-L6A memory leak? Wrong thread access? 🤔
Can repro in the Showtime app too. Always on top of all the issues @hirbod haha – thank you!