Several crashes in 0.9.13 version from NBPhoneNumberUtil
Hi,
We're seeing several crashes with the latest version (0.9.13) while trying to deal with the national number.
Root method for all these crashes (in NBPhoneNumberUtil.m):
- (NBPhoneNumber *)parse:(NSString *)numberToParse defaultRegion:(NSString *)defaultRegion error:(NSError **)error
Below are a few stack traces of the different crashes we observed. Is there something specific that we might be doing wrong which is the root cause for all these?
0 libobjc.A.dylib 0x0000000183edd7f4 objc_object::release() + 16 1 libPhoneNumber_iOS 0x00000001058de9a8 -[NBMetadataHelper getMetadataForRegion:] (NBMetadataHelper.m:167) 2 libPhoneNumber_iOS 0x00000001058e5f94 -[NBPhoneNumberUtil getMetadataForRegionOrCallingCode:regionCode:] (NBPhoneNumberUtil.m:1265) 3 libPhoneNumber_iOS 0x00000001058ee034 -[NBPhoneNumberUtil parseHelper:defaultRegion:keepRawInput:checkRegion:error:] (NBPhoneNumberUtil.m:3673) 4 libPhoneNumber_iOS 0x00000001058ed180 -[NBPhoneNumberUtil parse:defaultRegion:error:] (NBPhoneNumberUtil.m:3406)
========================================================================
0 libobjc.A.dylib 0x000000018328443c objc_msgSend + 28 1 libPhoneNumber_iOS 0x0000000105eda048 -[NBPhoneNumberUtil parseHelper:defaultRegion:keepRawInput:checkRegion:error:] (NBPhoneNumberUtil.m:3672) 2 libPhoneNumber_iOS 0x0000000105ed9180 -[NBPhoneNumberUtil parse:defaultRegion:error:] (NBPhoneNumberUtil.m:3406)
========================================================================
0 libobjc.A.dylib 0x00000001838357f4 objc_object::release() + 16 1 libPhoneNumber_iOS 0x000000010314ce20 -[NBPhoneNumberUtil maybeStripNationalPrefixAndCarrierCode:metadata:carrierCode:] (NBPhoneNumberUtil.m:3316) 2 libPhoneNumber_iOS 0x000000010314e158 -[NBPhoneNumberUtil parseHelper:defaultRegion:keepRawInput:checkRegion:error:] (NBPhoneNumberUtil.m:3703) 3 libPhoneNumber_iOS 0x000000010314d180 -[NBPhoneNumberUtil parse:defaultRegion:error:] (NBPhoneNumberUtil.m:3406)
========================================================================
0 libobjc.A.dylib 0x0000000181124430 objc_msgSend + 16 1 libPhoneNumber_iOS 0x000000010552be94 -[NBPhoneNumberUtil maybeExtractCountryCode:metadata:nationalNumber:keepRawInput:phoneNumber:error:] (NBPhoneNumberUtil.m:3097) 2 libPhoneNumber_iOS 0x000000010552daf8 -[NBPhoneNumberUtil parseHelper:defaultRegion:keepRawInput:checkRegion:error:] (NBPhoneNumberUtil.m:3632) 3 libPhoneNumber_iOS 0x000000010552d180 -[NBPhoneNumberUtil parse:defaultRegion:error:] (NBPhoneNumberUtil.m:3406
I believe this is a thread safety issue. You are using libPhoneNumber on multiple threads.
The 0.9.13 version of the library doesn't seem to be thread-safe. For example, the instance variable _cachedMetaData is read and written to in -[NBMetadataHelper getMetadataForRegion:] without thread synchronization or atomic properties, so there can be race conditions if multiple threads are using that method at the same time. The latest version of the code caches the metadata in an NSCache instead, so it shouldn't have the thread safety problem anymore.
Thanks @newacct ! We are working on some client side changes to make it thread safe. When can we expect the next version of the library to be released?