jetfire icon indicating copy to clipboard operation
jetfire copied to clipboard

NSRunLoop Crash!

Open mykoma opened this issue 8 years ago • 2 comments

I have met a crash at

[self.inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    [self.outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    [self.inputStream open];
    [self.outputStream open];
    size_t dataLen = [data length];
    [self.outputStream write:[data bytes] maxLength:dataLen];
    while (self.isRunLoop) {
        [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
    }

The Line [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]; always crash when I create many socket in a short time. Maybe there is a third sdk conflict with these above code.

And I spent half day to fix this problem , and finally I find a way to avoid this bug. The code is:

    [self.inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:@"JFRWebSocketRunLoopMode"];
    [self.outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:@"JFRWebSocketRunLoopMode"];
    [self.inputStream open];
    [self.outputStream open];
    size_t dataLen = [data length];
    [self.outputStream write:[data bytes] maxLength:dataLen];
    while (self.isRunLoop) {
        [[NSRunLoop currentRunLoop] runMode:@"JFRWebSocketRunLoopMode" beforeDate:[NSDate distantFuture]];
    }

I am not sure why this crash happend, neither not sure why my fix can works.

But I think should let you know this issue.

mykoma avatar Jan 15 '17 01:01 mykoma

I have the same crash

OlinJX avatar Mar 30 '17 07:03 OlinJX

I fixed the crash on my fork (with extra refactoring and design changes), the real issue was the ability to initialize multiple connections when calling [socket connect] a few times on a disconnected socket (created state marked asynchronously).

#67 Add blocking connect and move handling connection to dedicated NSThread

krosinski avatar Aug 29 '17 14:08 krosinski