nuclearace / Socket.IO-Client-Swift

socket.io-client for Swift
Other
361 stars 53 forks source link

Attempting to retain a deallocated object inside connect #84

Open ysholqamy opened 9 years ago

ysholqamy commented 9 years ago

Hello, I get an error when I try to deallocate the socket, the case is the following: sometimes I need to change the connect params of the socket so I deallocate the old socket and init a new one, the problem is if this is done just after connecting the old socket I get an error inside connect method saying attempting to retain a deallocated object in the last line inside the second dispatch_async. So any idea how I could fix that? Also, what is the best practice for re initializing a socket?

nuclearace commented 9 years ago

Are you connecting with a timeout?

ysholqamy commented 9 years ago

No

ysholqamy commented 9 years ago

I think I found the problem, engine.createWebSocket() calls webSocket.connect() and releases the created web socket , which will result in a race condition because the webSocket can still be accessed from within the async connect. I have no idea how to fix, I believe the only way is to make the closure in the async operation a strong retainer for the web socket instead of weak, still this would be a bad solution because it is generally a bad practice to strong reference an object from within a background operation.