Skip to content

Prevent NativeEventObserver crash during monitor events#83

Merged
robertherber merged 1 commit intokingstinct:mainfrom
joe2708:fix/native-observer-crash
Feb 2, 2026
Merged

Prevent NativeEventObserver crash during monitor events#83
robertherber merged 1 commit intokingstinct:mainfrom
joe2708:fix/native-observer-crash

Conversation

@joe2708
Copy link
Contributor

@joe2708 joe2708 commented Feb 2, 2026

I hit an intermittent iOS crash during DeviceActivity monitor event flows (save/sync/start-stop), with stack traces pointing to NativeEventObserver.registerListener and crash signatures like EXC_BAD_ACCESS / KERN_PROTECTION_FAILURE.

This PR hardens the native observer callback lifecycle:

  • Routes callback handling through NativeEventObserver and guards module access before calling sendEvent
  • Uses safer observer pointer ownership for callback lifetime
  • Makes unregister() nil-safe and clears observer pointer after removal
  • Adds deinit cleanup by calling unregister()

No JS API or feature behavior changes in this PR; this is an iOS native stability fix only to prevent unwanted crashes during saving schedules.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 2, 2026

Open in StackBlitz

npm i https://pkg.pr.new/kingstinct/react-native-device-activity@83

commit: 709d837

@robertherber robertherber merged commit e20fa61 into kingstinct:main Feb 2, 2026
2 checks passed
@robertherber
Copy link
Member

Thanks for your contribution @joe2708! Have gotten this as well at times

@joe2708
Copy link
Contributor Author

joe2708 commented Feb 2, 2026

Thanks for your contribution @joe2708! Have gotten this as well at times

Glad this resonates. After applying the patch, this reduced crashes during save/sync monitor churn by hardening the observer callback lifecycle. It significantly lowers this intermittent EXC_BAD_ACCESS path, but it can’t guarantee 100% crash-free behaviour for every edge case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants