Skip to content
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

iOS Sporadic Crash on SetItem #88

Open
ghost opened this issue Aug 3, 2017 · 15 comments
Open

iOS Sporadic Crash on SetItem #88

ghost opened this issue Aug 3, 2017 · 15 comments

Comments

@ghost
Copy link

ghost commented Aug 3, 2017

I am using this plugin through Ionic2 in an enterprise app with thousands of users each day. I have been seeing this crash report in XCode for a long time now:

image

As you can see, this has been happening on setItem() method. Here is the code from the NativeStorage.m file:

(void) setItem: (CDVInvokedUrlCommand*) command
{
	[self.commandDelegate runInBackground:^{
		CDVPluginResult* pluginResult = nil;
		NSString* reference = [command.arguments objectAtIndex:0];
		NSString* aString = [command.arguments objectAtIndex:1];

		if(reference!=nil)
		{
			NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
			[defaults setObject: aString forKey:reference];
			BOOL success = [defaults synchronize];
			if(success) pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsString:aString];
			else pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsInt:1]; //Write has failed

		}
		else
		{
			pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsInt:3]; //Reference was null
		}
		[self.commandDelegate sendPluginResult:pluginResult callbackId: command.callbackId];
	}];
}

And this is only happening every once in a while (not every time I use the setItem method). Because, as I said, I have thousands of users each day and this has, for example, only happened 73 times in the past two weeks.

image

The crash backtrace goes back to this line:

[defaults setObject: aString forKey:reference];

Could you please clarify what is this line doing?

@ghost
Copy link
Author

ghost commented Aug 3, 2017

Could this be related to this?
#36

Or could it be because I am calling nativeStorage.setItem multiple times at once, sometimes? E.g. I have setItem() calls like this in consecutive lines:

nativeStorage.setItem(key1, value1);
nativeStorage.setItem(key2, value2);

Would this cause a crash?

@LockonF
Copy link

LockonF commented Sep 6, 2017

It's been happening to me when I try to do even a single write with
nativeStorage.setIdem(key, value);

My full log is as follows

objc[63744]: Class PLBuildVersion is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices (0x11ededcc0) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices (0x11ec046f0). One of the two will be used. Which one is undefined.
2017-09-05 20:58:44.612 DNA[63744:9346586] Apache Cordova native platform version 4.4.0 is starting.
2017-09-05 20:58:44.613 DNA[63744:9346586] Multi-tasking -> Device: YES, App: YES
2017-09-05 20:58:44.708 DNA[63744:9346586] Using UIWebView
2017-09-05 20:58:44.709 DNA[63744:9346586] [CDVTimer][handleopenurl] 0.052989ms
2017-09-05 20:58:44.711 DNA[63744:9346586] [CDVTimer][intentandnavigationfilter] 1.925945ms
2017-09-05 20:58:44.712 DNA[63744:9346586] [CDVTimer][gesturehandler] 0.064969ms
2017-09-05 20:58:44.731 DNA[63744:9346586] [CDVTimer][splashscreen] 18.769979ms
2017-09-05 20:58:44.735 DNA[63744:9346586] [CDVTimer][statusbar] 4.305959ms
2017-09-05 20:58:44.738289-0500 DNA[63744:9346586] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /Users/lockon/Library/Developer/CoreSimulator/Devices/41E58B03-47EA-4E9B-90DE-B8CDDA4829BB/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2017-09-05 20:58:44.738909-0500 DNA[63744:9346586] [MC] Filtering mail sheet accounts for bundle ID: com.netlogistik.dna, source account management: 1
2017-09-05 20:58:44.741156-0500 DNA[63744:9346586] [MC] Result: NO
2017-09-05 20:58:44.741 DNA[63744:9346586] [CDVTimer][socialsharing] 5.557001ms
2017-09-05 20:58:44.742 DNA[63744:9346586] [CDVTimer][keyboard] 0.939965ms
2017-09-05 20:58:44.742 DNA[63744:9346586] [CDVTimer][TotalPluginStartup] 33.038020ms
2017-09-05 20:58:45.119 DNA[63744:9346586] Resetting plugins due to page load.
2017-09-05 20:58:47.467 DNA[63744:9346586] Finished load of: http://192.168.1.69:8100/
2017-09-05 20:58:48.017 DNA[63744:9346586] Ionic Native: deviceready event fired after 2365 ms
2017-09-05 20:58:51.388 DNA[63744:9346682] -[NSNull length]: unrecognized selector sent to instance 0x11057b180
2017-09-05 20:58:51.390 DNA[63744:9346682] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized selector sent to instance 0x11057b180'
*** First throw call stack:
(
	0   CoreFoundation                      0x00000001102beb0b __exceptionPreprocess + 171
	1   libobjc.A.dylib                     0x000000010fcfa141 objc_exception_throw + 48
	2   CoreFoundation                      0x000000011032e134 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
	3   CoreFoundation                      0x0000000110245840 ___forwarding___ + 1024
	4   CoreFoundation                      0x00000001102453b8 _CF_forwarding_prep_0 + 120
	5   CoreFoundation                      0x000000011027eb56 _CFPrefsEncodeKeyValuePairIntoMessage + 70
	6   CoreFoundation                      0x000000011027e93c -[CFPrefsPlistSource sendMessageSettingValue:forKey:] + 124
	7   CoreFoundation                      0x0000000110328daa -[CFPrefsPlistSource alreadylocked_setValues:forKeys:count:] + 794
	8   CoreFoundation                      0x00000001102e5c58 -[CFPrefsSource setValues:forKeys:count:removeValuesForKeys:count:] + 264
	9   CoreFoundation                      0x0000000110211620 -[CFPrefsSource setValues:forKeys:count:] + 32
	10  CoreFoundation                      0x000000011031faf6 -[CFPrefsSearchListSource alreadylocked_setValues:forKeys:count:] + 454
	11  CoreFoundation                      0x00000001102e5c58 -[CFPrefsSource setValues:forKeys:count:removeValuesForKeys:count:] + 264
	12  CoreFoundation                      0x0000000110211620 -[CFPrefsSource setValues:forKeys:count:] + 32
	13  CoreFoundation                      0x0000000110254fe9 -[CFPrefsSource setValue:forKey:] + 57
	14  CoreFoundation                      0x0000000110321a4f __108-[_CFXPreferences(SearchListAdditions) withSearchListForIdentifier:container:cloudConfigurationURL:perform:]_block_invoke + 319
	15  CoreFoundation                      0x000000011032124d normalizeQuintuplet + 317
	16  CoreFoundation                      0x0000000110321909 -[_CFXPreferences(SearchListAdditions) withSearchListForIdentifier:container:cloudConfigurationURL:perform:] + 105
	17  CoreFoundation                      0x000000011030bc15 -[_CFXPreferences setValue:forKey:appIdentifier:container:configurationURL:] + 261
	18  CoreFoundation                      0x0000000110254f34 _CFPreferencesSetAppValueWithContainer + 68
	19  Foundation                          0x000000010f7f9790 -[NSUserDefaults(NSUserDefaults) setObject:forKey:] + 55
	20  DNA                                 0x000000010f19df22 __25-[NativeStorage setItem:]_block_invoke + 290
	21  libdispatch.dylib                   0x00000001129ad4a6 _dispatch_call_block_and_release + 12
	22  libdispatch.dylib                   0x00000001129d605c _dispatch_client_callout + 8
	23  libdispatch.dylib                   0x00000001129b5dcd _dispatch_queue_override_invoke + 1321
	24  libdispatch.dylib                   0x00000001129b7ec4 _dispatch_root_queue_drain + 634
	25  libdispatch.dylib                   0x00000001129b7bef _dispatch_worker_thread3 + 123
	26  libsystem_pthread.dylib             0x0000000112e285a2 _pthread_wqthread + 1299
	27  libsystem_pthread.dylib             0x0000000112e2807d start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException

@alokrajiv
Copy link
Collaborator

@GillesC could you have a look at the 2 above posts. Maybe you can help. Thanks!

@alokrajiv
Copy link
Collaborator

alokrajiv commented Oct 11, 2017

@Maziar-Fotouhi
Based on @LockonF 's log...do you think we are battling this framework error discussed: https://forums.developer.apple.com/thread/63254 &
https://stackoverflow.com/questions/39520499/class-plbuildversion-is-implemented-in-both-frameworks

@ghost
Copy link
Author

ghost commented Oct 11, 2017

@alokrajiv I believe that PLBuildVersion being defined twice is not causing the crash. It is letting it go through and using one of the definitions. I think the exception is raised later on at the last two lines before the stacktrace.
Based on 1 and 2 and 3 we might be missing a null check somewhere.

@alokrajiv
Copy link
Collaborator

@Maziar-Fotouhi interesting...lets explore this further with special focus on your insights.

cc @GillesC

@sum1190
Copy link

sum1190 commented Nov 28, 2017

Hi, I've created an app that use this plugin and unfortunately I get the same error. After some analysis done on the routine setItem in the file NativeStorage.m, I've setted the line 214 in this way

if(reference!=nil && (NsNull*) aString == [NsNull null]) { ...

I'm not an Objective-C developer and I don't know if this fix is really useful but in this way my app doesn't crash anymore.

@ghost
Copy link
Author

ghost commented Nov 29, 2017

@alokrajiv Is this a viable fix?

@alokrajiv
Copy link
Collaborator

Very Interesting ... can one of you check if branch issue-88-patch-1 solves the issue?

Its based on @sum1190 's fix!

@ghost
Copy link
Author

ghost commented Nov 30, 2017

@alokrajiv Unfortunately I am seeing this error sporadically right now. So, I won't really be able to test it. Sorry!

@sum1190
Copy link

sum1190 commented Nov 30, 2017

In my case, the app crash occurred at the first start of the app. I've published it on Apple's TestFlight, at the first start the app crash, on the second start no.
So I've reproduced the error by uninstalling it and install it again. You can try in this way I think.

@ben-pritchard
Copy link

Is this issue still open? And has anybody experienced this happening via an Ionic 1 app? My iOS 9 app will crash on $cordovaNativeStorage.setItem() with some predictability, but not on every call to it. On an iOS11 device, it does not crash.

@alokrajiv
Copy link
Collaborator

There seems to be less occurrence of reporting this error at the moment.

@eddyorzsik
Copy link

hi @alokrajiv, is there an ETA for a new release with the iOS crash bug fixed?

@alokrajiv
Copy link
Collaborator

@GillesC I thought we already have this fix in a release. It's in master as far as I'm aware.

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

No branches or pull requests

5 participants