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

crash on isReadableOrWritable #123

Closed
shinma opened this issue Feb 22, 2018 · 4 comments
Closed

crash on isReadableOrWritable #123

shinma opened this issue Feb 22, 2018 · 4 comments

Comments

@shinma
Copy link

shinma commented Feb 22, 2018

I'm struggling with one crash since version 0.12.87 (so I'm stuck on 0.12.86 which works fine). It happens almost every time when I start application and in-between running. I was hoping to see fix in each version but it did happen so I'm writing this issue. It always happens when I try to execute isReadableOrWritable. Please take a look at the code below.

Device: any iPhone 64-bit
iOS: 10 or higher
Xcode: 9.2 (9C40b)

    guard !socket.isConnected else {
        throw CommunicationError.connectionError
    }
    
    do {
        try socket.connect(to: hostName, port: port)
    } catch {
        throw CommunicationError.connectionError
    }
    
    do {
        try socket.setReadTimeout(value: 20000)
    } catch {
        throw CommunicationError.connectionError
    }
    
    do {
        try socket.setWriteTimeout(value: 4000)
    } catch {
        throw CommunicationError.connectionError
    }
    
    do {
        try socket.setBlocking(mode: true)
    } catch {
        throw CommunicationError.connectionError
    }
    
    //Write
    let dataSentCount = try socket.write(from: dataToSend)
    
    guard dataSentCount > 0 else {
        throw CommunicationError.socketWriteError
    }
    
    var isReadable = false
    
    //Read
    while !isReadable {
        do {
            let tuple = try socket.isReadableOrWritable(waitForever: false, timeout: 10)
            
            if tuple.readable {
                break
            }
            
            isReadable = tuple.readable
        } catch {
            throw CommunicationError.socketReadError
        }
        
        Thread.sleep(forTimeInterval: 0.5)
    }

zrzut ekranu 2018-02-22 o 09 22 19

zrzut ekranu 2018-02-22 o 10 14 59

I have used Debug version to pinpoint line causing error.

@billabt
Copy link
Collaborator

billabt commented Feb 22, 2018

I suspect that this problem and also the problem being seen in issue #125 is related to changes made in PR #110 and it's related PRs. I never saw any of these problems prior to accepting that PR.

@AlanQuatermain: Any ideas what could be causing this? With the rash of bugs that have arisen since accepting this PR, I'm considering rolling it back again.

@AlanQuatermain
Copy link
Contributor

AlanQuatermain commented Feb 22, 2018 via email

@billabt
Copy link
Collaborator

billabt commented Feb 22, 2018

The unit tests are covering most of these code paths but probably not to the extent that it could catch these problems. They seem to edge cases.

Take a look at issue #120. This one is very similar to this case and the user reporting it provided code you can use in a playground. Maybe trying that will give you a clue. I'm still recovering from surgery and unfortunately can't sit (don't ask, 🤪) too long at the computer or I would've tried it before now.

@billabt
Copy link
Collaborator

billabt commented Feb 23, 2018

Fixed in 0.12.93.

@billabt billabt closed this as completed Feb 23, 2018
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