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

Crashes in multi threaded app usage. #19

Closed
skathiresan opened this issue Mar 16, 2016 · 9 comments
Closed

Crashes in multi threaded app usage. #19

skathiresan opened this issue Mar 16, 2016 · 9 comments

Comments

@skathiresan
Copy link

I get the same crash dump a lot of times. Every time, the thread that this is being done is some background thread.
I noticed you are starting the pingFoundation in main thread. Do we also need to stop it in main thread?

The below is the dump of the crash generated by Hockey

Thread 11 Crashed:
0x0000000181e459cc CFRelease + 1128
0x00000001005f5ec0 -PingFoundation stopDataTransfer
0x00000001005f5efc -PingFoundation stop
0x00000001005f62c0 -PingHelper pingWithBlock:
0x00000001005f77a0 -RealReachability reachabilityWithBlock:
0x00000001005f7e40 __41-[RealReachability autoCheckReachability]_block_invoke (RealReachability.m:253)
0x00000001819b9630 _dispatch_call_block_and_release + 20
0x00000001819b95f0 _dispatch_client_callout + 12
0x00000001819c4e7c _dispatch_after_timer_callback + 88
0x00000001819b95f0 _dispatch_client_callout + 12
0x00000001819d0204 _dispatch_source_latch_and_call + 2552
0x00000001819bbae4 _dispatch_source_invoke + 804
0x00000001819c7504 _dispatch_root_queue_drain + 724
0x00000001819c7224 _dispatch_worker_thread3 + 108
0x0000000181bcd470 _pthread_wqthread + 1088
0x0000000181bcd020 start_wqthread + 0

@dustturtle
Copy link
Owner

can you describe more about how to use realreachability?I have never seen this in my app. The usage is like the demo .Or can you reproduce it with my latest demo? Thank you so much!

@dustturtle
Copy link
Owner

Would you please check if you called "[GLobalRealReachability startNotifier];" in background thread?
You can send email to me, either. Thank you! openglnewbee@163.com

@dustturtle
Copy link
Owner

Could you please give me a feedback? Thank you

@sherlockyao
Copy link

Hi, I came across a crash too due to PingFoundation, here is the logs

Thread 13 Crashed:
0 CFNetwork 0x00000001813e5e6c CFHostUnscheduleFromRunLoop + 32
1 ****** 0x000000010025bc94 -[PingFoundation stopHostResolution] + 80
2 ****** 0x000000010025bd08 -[PingFoundation stop] + 28
3 ****** 0x00000001001c5e10 -[PingHelper pingWithBlock:] + 216
4 ****** 0x00000001002923ac -[RealReachability reachabilityWithBlock:] + 268
5 ****** 0x0000000100292b7c __41-[RealReachability autoCheckReachability]_block_invoke + 40
6 libdispatch.dylib 0x0000000180825630 _dispatch_call_block_and_release + 24
7 libdispatch.dylib 0x00000001808255f0 _dispatch_client_callout + 16
8 libdispatch.dylib 0x0000000180830e7c _dispatch_after_timer_callback + 92
9 libdispatch.dylib 0x00000001808255f0 _dispatch_client_callout + 16
10 libdispatch.dylib 0x000000018083c204 _dispatch_source_latch_and_call + 2556
11 libdispatch.dylib 0x0000000180827ae4 _dispatch_source_invoke + 808
12 libdispatch.dylib 0x0000000180833504 _dispatch_root_queue_drain + 728
13 libdispatch.dylib 0x0000000180833224 _dispatch_worker_thread3 + 112
14 libsystem_pthread.dylib 0x0000000180a39470 _pthread_wqthread + 1092
15 libsystem_pthread.dylib 0x0000000180a39020 start_wqthread + 4

don't know why, I've checked the code and I didn't call [GLobalRealReachability startNotifier] in background thread

@dustturtle
Copy link
Owner

I have made some modifying, please try again! Thank you @sherlockyao @skathiresan

@skathiresan
Copy link
Author

thanks @dustturtle .. Will keep you posted if i see any issue,
Did you also want to upgrade the pod version please?
Great work with this API !! thank you.

@dustturtle
Copy link
Owner

I would like to watch for some days.New pod version will be released in this week.Thank you so much! @skathiresan

@skathiresan
Copy link
Author

@dustturtle I have been testing this further more with your latest commit -
One thing that i observed is that there were some false pingTimeOut being executed and hence we were going to the "Not" reachable state when there was a valid connection. Also the 2 seconds seemed too quick to time out.. I modified the code like below for my tests and it worked for the variety of tests i did.. what do you think?

PingHelper

        if (![[NSThread currentThread] isMainThread]) {
            dispatch_sync(dispatch_get_main_queue(), ^{

                __strong __typeof(weakSelf)strongSelf = weakSelf;
                // safe protection for exceptional situation, background app or multi-thread, eg.
                [self.pingFoundation stop];
                //Cancel any previous pingTimeout before queuing new ones
                [[self class] cancelPreviousPerformRequestsWithTarget:strongSelf selector:@selector(pingTimeOut) object:nil];
                strongSelf.isPinging = YES;
                [strongSelf.pingFoundation start];

                [strongSelf performSelector:@selector(pingTimeOut) withObject:nil afterDelay:60.0f];
            });
        }
        else
        {
            // safe protection for exceptional situation, background app or multi-thread, eg.
            [self.pingFoundation stop];
            [[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(pingTimeOut) object:nil];

            self.isPinging = YES;
            [self.pingFoundation start];

            [self performSelector:@selector(pingTimeOut) withObject:nil afterDelay:60.0f];
        }

The below change to induce a minor delay before checking for "Real" reachability helped fix some false alarms of the host not reachable.

RealReachability

- (void)localConnectionChanged:(NSNotification *)notification
{
    LocalConnection *lc = (LocalConnection *)notification.object;
    LocalConnectionStatus lcStatus = [lc currentLocalConnectionStatus];
    NSLog(@"currentLocalConnectionStatus:%@",@(lcStatus));

    NSDictionary *inputDic = @{kEventKeyID:@(RREventLocalConnectionCallback), kEventKeyParam:[self paramValueFromStatus:lcStatus]};
    NSInteger rtn = [self.engine receiveInput:inputDic];

    if (rtn == 0) // state changed & state available, post notification.
    {
        if ([self.engine isCurrentStateAvailable])
        {
            // already in main thread.
            [[NSNotificationCenter defaultCenter] postNotificationName:kRealReachabilityChangedNotification
                                                                object:self];
            // To make sure your reachability is "Real".
            [self performSelector:@selector(reachabilityWithBlock:) withObject:nil afterDelay:0.3];
        }
    }
}

All these tests were performed in multi threaded application.

@dustturtle
Copy link
Owner

solved already

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

3 participants