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

Bad Access Error on listen thread when pinging multiple IPs #4

Open
micahnap opened this issue Jan 27, 2015 · 7 comments
Open

Bad Access Error on listen thread when pinging multiple IPs #4

micahnap opened this issue Jan 27, 2015 · 7 comments

Comments

@micahnap
Copy link

Hello again,

I'm trying to see if this library is capable of pinging multiple IP's. What I'm doing is basically making it ping an entire range of IPs. It seems possible, but occasionally I get this EXC_BAD_ACCESS error on this line of code that lives in the GBPing.m in the listenOnce method:

GBPingSummary *pingSummary = [(GBPingSummary *)self.pendingPings[key] copy];

I'm setting it up like this

GBPing *pinger;
    pinger = [[GBPing alloc] init];
    pinger.host = ipAddress;
    pinger.delegate = self;
    pinger.timeout = 1.0;
    pinger.pingPeriod = 0.9;

    [pinger setupWithBlock:^(BOOL success, NSError *error) { //necessary to resolve hostname
        if (success) {
            //start pinging
            [pinger startPinging];

            //stop it after 5 seconds
            [NSTimer scheduledTimerWithTimeInterval:5 repeats:NO withBlock:^{

                [pinger stop];
            }];
        }
        else {
            NSLog(@"failed to start");
        }
    }];

and pulling in the IP addresses like this - 5 at a time in 3 second chunks

-(void)pingIPRange{
    dispatch_async(backgroundQueue, ^{
        for (int i = hostCount; i < hostCount + 5; i++) {
            NSString *ip = [NSString stringWithFormat:@"192.168.11.%i", i];
            [self pingIPRangeForBroadcastIP:nil withIP:ip];
        }
        [self restartTimer];
    });
}

and then doing this in the reply delegate to kick off the next ping

- (void)restartTimer{
    hostCount += 5;
    if (hostCount > 254){
        hostCount = 101;
    }
    dispatch_async(dispatch_get_main_queue(), ^{
        [timer invalidate];
        timer = nil;
        timer = [NSTimer scheduledTimerWithTimeInterval:3.0
                                                 target:self
                                               selector:@selector(pingIPRange)
                                               userInfo:nil
                                                repeats:YES];
    });
}

starting the host count at 101. Apologies for my ignorance. Just want to see if this is possible at all and if so what the proper way might be to set it up. Thanks!

@micahnap micahnap reopened this Jan 30, 2015
@mikumi
Copy link

mikumi commented Jul 7, 2015

I'm having this issue as well, but haven't found out why it's happening yet

@cpage13
Copy link

cpage13 commented Aug 1, 2015

Same here. It is very difficult to consistently reproduce. I have a feeling it has to do with the fact that pendingPings been accessed and mutated in different threads. Maybe wrapping them in @synchronized could help?

@lmirosevic
Copy link
Owner

Can you see if 1.3.1 still exhibits this behaviour?

@cpage13
Copy link

cpage13 commented Oct 21, 2015

So far looks good. Thanks for looking into this.

@ftnn
Copy link

ftnn commented Nov 25, 2015

1.3.3 still has this issue;

Crashed: listenThread

EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000000

0 CoreFoundation -[__NSDictionaryM objectForKey:] + 229
1 GBPing.m line 382 -[GBPing listenOnce]
2 GBPing.m line 346 -[GBPing listenLoop]

@synchronized(self) is needed to protect multi-thread access

@alexjessecole
Copy link

This is indeed still an issue in 1.3.3.

Crashed: listenThread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000000

Any help getting this cleared up would be amazing and greatly appreciated!

@PabloAlejandro
Copy link

Same issue here

EXC_BAD_ACCESS (code=1, address=0x0)

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

7 participants