swamp
swamp copied to clipboard
Crashes sometimes when leaving view controller
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.
Is this project still maintained?
I don't think so, I have created a fork for my company usage, you can use it if you want a maintained lib: https://github.com/pitput/SwiftWamp