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 sometimes when leaving view controller #12

Open
LucasVanDongen opened this issue Dec 10, 2016 · 2 comments
Open

Crashes sometimes when leaving view controller #12

LucasVanDongen opened this issue Dec 10, 2016 · 2 comments

Comments

@LucasVanDongen
Copy link

I have a working WAMP implementation that crashes every 50 times or so. It happens when I leave the screen and the disconnect() method gets called:

class WampConnector: NSObject {
    static var authid = ""
    let wampEndpoint = "ws://wamp.workspace-beta.nl:9090"
    let realm = "workspace"
    let swampTransport: WebSocketSwampTransport
    let swampSession: SwampSession
    
    init?(withDelegate delegate: SwampSessionDelegate) {
        let url = URL(string: wampEndpoint) ?? URL(fileURLWithPath: "")
        
        swampTransport = WebSocketSwampTransport(wsEndpoint:  url)
        swampSession = SwampSession(realm: realm, transport: swampTransport, authmethods: ["ticket"])
        swampSession.delegate = delegate

        swampSession.connect()
        
        super.init()
    }
    
    func disconnect() {
        swampSession.disconnect("Leaving screen")
    }
}

The error occurs when force-unwrapping the serializer and/or data.

    fileprivate func sendMessage(_ message: SwampMessage){
        let marshalledMessage = message.marshal()
        let data = self.serializer!.pack(marshalledMessage as [Any])!
        self.transport.sendData(data)
    }

I notice force unwrapping is the default way to handle optionals in the library, probably to ensure errors get caught early instead of just returning after a guard statement and failing silently. But I think this error occurs because of some kind of race condition that's really hard to reproduce and it might be safer to guard let everything and return when the serializer is gone or no data instance is created.

@LucasVanDongen
Copy link
Author

Is this project still maintained?

@danysousa
Copy link

danysousa commented Mar 6, 2017 via email

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

2 participants