Giter Club home page Giter Club logo

Comments (10)

iziz avatar iziz commented on July 30, 2024

I see.. maybe it cause from static function (nsregularexpression)
I'll find out the reason and fix it ASAP.

from libphonenumber-ios.

futuretap avatar futuretap commented on July 30, 2024

That makes sense. Just after posting this I saw another crash, this time crashing in libicucore:

Thread 9 Crashed:
0   libsystem_kernel.dylib               0x0000000198cc7270 __pthread_kill + 8
1   libsystem_pthread.dylib              0x0000000198d65170 pthread_kill + 108
2   libsystem_c.dylib                    0x0000000198c3eb18 abort + 108
3   libsystem_malloc.dylib               0x0000000198d023e4 nanozone_error + 316
4   libsystem_malloc.dylib               0x0000000198d02550 _nano_malloc_check_clear + 360
5   libsystem_malloc.dylib               0x0000000198d01064 nano_malloc + 40
6   libsystem_malloc.dylib               0x0000000198cf13e4 malloc_zone_malloc + 112
7   libsystem_malloc.dylib               0x0000000198cf5a04 malloc + 52
8   libicucore.A.dylib                   0x0000000197f36664 icu::UnicodeSet::UnicodeSet() + 104
9   libicucore.A.dylib                   0x0000000197ff8214 icu::RuleBasedTimeZone::getLocalDelta(int, int, int, int, int, int) const + 7076
10  libicucore.A.dylib                   0x0000000197ff6afc icu::RuleBasedTimeZone::getLocalDelta(int, int, int, int, int, int) const + 1164
11  libicucore.A.dylib                   0x000000019800ecb8 icu::RegexPattern::compile(UText*, unsigned int, UParseError&, UErrorCode&) + 280
12  libicucore.A.dylib                   0x000000019804d174 uregex_open + 336
13  Foundation                           0x0000000187b79a34 -[NSRegularExpression initWithPattern:options:error:] + 400
14  Foundation                           0x0000000187c885d4 +[NSRegularExpression regularExpressionWithPattern:options:error:] + 68
15  WhereToKit                           0x00000001005b0948 -[NBPhoneNumberUtil regularExpressionWithPattern:options:error:] (NBPhoneNumberUtil.m:167)
16  WhereToKit                           0x00000001005b07bc -[NBPhoneNumberUtil entireRegularExpressionWithPattern:options:error:] (NBPhoneNumberUtil.m:144)
17  WhereToKit                           0x00000001005be318 -[NBPhoneNumberUtil matchesEntirely:string:] (NBPhoneNumberUtil.m:3848)
18  WhereToKit                           0x00000001005b8c28 -[NBPhoneNumberUtil isNumberMatchingDesc:numberDesc:] (NBPhoneNumberUtil.m:2255)
19  WhereToKit                           0x00000001005b890c -[NBPhoneNumberUtil getNumberTypeHelper:metadata:] (NBPhoneNumberUtil.m:2209)
20  WhereToKit                           0x00000001005b924c -[NBPhoneNumberUtil getRegionCodeForNumberFromRegionList:regionCodes:] (NBPhoneNumberUtil.m:2377)
21  WhereToKit                           0x00000001005b9034 -[NBPhoneNumberUtil getRegionCodeForNumber:] (NBPhoneNumberUtil.m:2350)
22  WhereToKit                           0x00000001005b8c7c -[NBPhoneNumberUtil isValidNumber:] (NBPhoneNumberUtil.m:2272)

There was also another active thread in the crash log that had accessed libPhoneNumber before.

Thanks for looking into this.

from libphonenumber-ios.

iziz avatar iziz commented on July 30, 2024

Thank you. and sorry for "not safe" multile thread issue. :)

from libphonenumber-ios.

iziz avatar iziz commented on July 30, 2024

Please check with latest code. I removed static NSRegularExpressions.

from libphonenumber-ios.

futuretap avatar futuretap commented on July 30, 2024

Thanks. I'll integrate the code and ship the next update with it. Should I see any crashes, I'll let you know!

from libphonenumber-ios.

iziz avatar iziz commented on July 30, 2024

OK, Thank you very much.

from libphonenumber-ios.

futuretap avatar futuretap commented on July 30, 2024

So I shipped the update and received one crash report so far, caused by NBPhoneNumberUtil:

Thread 13 Crashed:
0   libsystem_kernel.dylib               0x0000000195373270 __pthread_kill + 8
1   libsystem_pthread.dylib              0x0000000195411170 pthread_kill + 108
2   libsystem_c.dylib                    0x00000001952eab18 abort + 108
3   libsystem_malloc.dylib               0x00000001953ae3e4 nanozone_error + 316
4   libsystem_malloc.dylib               0x00000001953ae550 _nano_malloc_check_clear + 360
5   libsystem_malloc.dylib               0x00000001953ad064 nano_malloc + 40
6   libsystem_malloc.dylib               0x000000019539d3e4 malloc_zone_malloc + 112
7   libsystem_malloc.dylib               0x00000001953a1a04 malloc + 52
8   libicucore.A.dylib                   0x00000001945e2664 icu::UnicodeSet::UnicodeSet() + 104
9   libicucore.A.dylib                   0x00000001946a4214 icu::RuleBasedTimeZone::getLocalDelta(int, int, int, int, int, int) const + 7076
10  libicucore.A.dylib                   0x00000001946a2afc icu::RuleBasedTimeZone::getLocalDelta(int, int, int, int, int, int) const + 1164
11  libicucore.A.dylib                   0x00000001946bacb8 icu::RegexPattern::compile(UText*, unsigned int, UParseError&, UErrorCode&) + 280
12  libicucore.A.dylib                   0x00000001946f9174 uregex_open + 336
13  Foundation                           0x0000000184225a34 -[NSRegularExpression initWithPattern:options:error:] + 400
14  Foundation                           0x00000001843345d4 +[NSRegularExpression regularExpressionWithPattern:options:error:] + 68
15  WhereToKit                           0x00000001006184d4 -[NBPhoneNumberUtil regularExpressionWithPattern:options:error:] (NBPhoneNumberUtil.m:167)
16  WhereToKit                           0x0000000100618a38 -[NBPhoneNumberUtil replaceStringByRegex:regex:withTemplate:] (NBPhoneNumberUtil.m:242)
17  WhereToKit                           0x000000010061a9ac -[NBPhoneNumberUtil extractPossibleNumber:] (NBPhoneNumberUtil.m:530)
18  WhereToKit                           0x0000000100624d64 -[NBPhoneNumberUtil buildNationalNumberForParsing:nationalNumber:] (NBPhoneNumberUtil.m:3583)
19  WhereToKit                           0x00000001006240f4 -[NBPhoneNumberUtil parseHelper:defaultRegion:keepRawInput:checkRegion:error:] (NBPhoneNumberUtil.m:3391)
20  WhereToKit                           0x00000001006239e0 -[NBPhoneNumberUtil parse:defaultRegion:error:] (NBPhoneNumberUtil.m:3251)

Looks like the exact same backtrace. This time, there was no other active thread using NBPhoneNumberUtil, though.

from libphonenumber-ios.

iziz avatar iziz commented on July 30, 2024

I'm afraid that I can't raise that crash.
Could you tell me your execution environment ?
and, see below... (my test code)

- (NSString *)stringWithRandomNumber
{
    NSString *numbers = @"0123456789";
    NSMutableString *randomString = [NSMutableString stringWithCapacity:11];

    for (int i=0; i<12; i++) {
        [randomString appendFormat: @"%C", [numbers characterAtIndex: arc4random() % [numbers length]]];
    }

    return randomString;
}


- (NSString *)randomRegion
{
    NBMetadataHelper *aHelper = [[NBMetadataHelper alloc] init];
    NSDictionary *metadata = [[aHelper getAllMetadata] objectAtIndex:(arc4random() % [aHelper getAllMetadata].count)];
    if (metadata) {
        NSString *region = [metadata objectForKey:@"code"];
        if (region) {
            return region;
        }
    }

    return nil;
}


- (void)testForMultithread
{
    NBPhoneNumberUtil *aUtil = [[NBPhoneNumberUtil alloc] init];
    NSString *testRegion = [self randomRegion];

    if (!testRegion) {
        return;
    }

    NSLog(@"- START [%@]", testRegion);

    dispatch_async(dispatch_get_main_queue(), ^{
        NSError *error = nil;

        for (int i=0; i<1000; i++) {
            [aUtil parse:[self stringWithRandomNumber] defaultRegion:testRegion error:&error];
            if (error && ![error.domain isEqualToString:@"INVALID_COUNTRY_CODE"]) {
                NSLog(@"error [%@]", [error localizedDescription]);
            }
            error = nil;
        }

        NSLog(@"OK [%@]", testRegion);
    });
}


- (void)testWithGCD
{
    for (int i = 0; i<1000; i++) {
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
            [self testForMultithread];
        });
    }
}

from libphonenumber-ios.

futuretap avatar futuretap commented on July 30, 2024

I'm creating (and releasing) my NBPhoneNumberUtil objects on the fly on a background thread. Looking over your tests, it seems you're running -parse: completely on the main thread, no?

I'll probably have to write some concurrency tests for my use case…

from libphonenumber-ios.

iziz avatar iziz commented on July 30, 2024

Yes, please show me. I will test it.

from libphonenumber-ios.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.