-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NSArrayM was mutated while being enumerated #1943
Comments
Here is a stack trace with more information:
|
I think I fixed the bug. While working on the app I noticed a method getting more calls than it should, fixed that and now I cannot reproduce the error anymore. The method that was being called returns the device's information and registers a push notification handler. |
I have actually run into this issue. Hard to reproduce reliably but it happens when you remove event listeners while there are events being triggered. I've worked around it in my own code so it won't trigger this time around, but it's a real synchronization problem in Capacitor. The "easy" fix is to iterate by index: diff --git a/ios/Capacitor/Capacitor/CAPPlugin.m b/ios/Capacitor/Capacitor/CAPPlugin.m
index f0fe9e14..fe153c0a 100644
--- a/ios/Capacitor/Capacitor/CAPPlugin.m
+++ b/ios/Capacitor/Capacitor/CAPPlugin.m
@@ -99,10 +99,14 @@
}
return;
}
-
- for(CAPPluginCall *call in listenersForEvent) {
- CAPPluginCallResult *result = [[CAPPluginCallResult alloc] init:data];
- call.successHandler(result, call);
+
+ for (int i=0; i < listenersForEvent.count; i++) {
+ CAPPluginCall *call = listenersForEvent[i];
+ if (call != nil) {
+ CAPPluginCallResult *result = [[CAPPluginCallResult alloc] init:data];
+ call.successHandler(result, call);
+ }
+ }
}
} ...although it could technically drop/miss events because of timing. The "real" fix is to probably use a serial queue of some kind to be sure actions on the event listeners are not all done simultaneously. |
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out. |
While testing on iOS I saw the app freeze and display the error below on xcode. I have no experience with the native code part of Capacitor and don't know what to do with it. Is it Capacitor related, OS X Catalina/iOS 13 related? Any information would be great!
Capacitor 1.2.0
iOS 13.1 beta 2
OS X Mojave 10.14.5
The text was updated successfully, but these errors were encountered: