Closed paulw11 closed 5 years ago
Actually this code doesn't fix it :(
@paulw11 could you write a failing test that reproduces this issue? A PR that fixes the problem is also appreciated if you find the solution.
@adolfo Hi, I'm having the same issue, it happens not regularly, I just had to restart the app multiple times and it happens 1 time out of 10. It crashed with BAD_ACCESS exception on currentRunLoop.run()
I simply moved the let currentRunLoop = RunLoop.current
out of the queue scope,
Like this..
let currentRunLoop = RunLoop.current sessionQueue.async { [weak self] in inputStream?.schedule(in: currentRunLoop, forMode: .defaultRunLoopMode) ..... currentRunLoop.run() }
The app stop crashing.
I guess it happened due to the currentRunLoop
is released. (not sure for the root cause)
Hope it helps!
Resolved in #40
I was getting a crash in SwiftMQTT if there was a short period between the creation and dispose of an
MQTTSessionStream
- the problem is that the[weak self]
has been released before the async block executes on thesessionQueue
. The following check addresses the issue:sessionQueue.async { [weak self] in if self != nil { let currentRunLoop = RunLoop.current inputStream?.schedule(in: currentRunLoop, forMode: .defaultRunLoopMode) outputStream?.schedule(in: currentRunLoop, forMode: .defaultRunLoopMode) inputStream?.open() outputStream?.open() if ssl { let securityLevel = StreamSocketSecurityLevel.negotiatedSSL.rawValue inputStream?.setProperty(securityLevel, forKey: .socketSecurityLevelKey) outputStream?.setProperty(securityLevel, forKey: .socketSecurityLevelKey) } if timeout > 0 { DispatchQueue.global().asyncAfter(deadline: .now() + timeout) { self?.connectTimeout() } }