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

NSRunLoop Crash! #59

Open
mykoma opened this issue Jan 15, 2017 · 2 comments
Open

NSRunLoop Crash! #59

mykoma opened this issue Jan 15, 2017 · 2 comments

Comments

@mykoma
Copy link

mykoma commented Jan 15, 2017

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.

@OlinJX
Copy link

OlinJX commented Mar 30, 2017

I have the same crash

idomizrachi pushed a commit to idomizrachi/jetfire that referenced this issue May 3, 2017
@krosinski
Copy link

krosinski commented Aug 29, 2017

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

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