-
Notifications
You must be signed in to change notification settings - Fork 73
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 if MQTTSession stream is created and disposed of quickly #33
Comments
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
The app stop crashing. 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()
}
}
The text was updated successfully, but these errors were encountered: