daltoniam / Starscream

Websockets in swift for iOS and OSX
Apache License 2.0
8.37k stars 1.21k forks source link

Crash in FoundationStream.cleanup() #566

Closed jincc closed 6 years ago

jincc commented 6 years ago

When I was using socket.io.swift, a crash occurred, and the final stack was located in starscream. I suspect it might be a concurrency issue, and I can give good suggestions when I am in trouble.


0   libobjc.A.dylib                 objc_msgSend + 16
specialized _VariantDictionaryBuffer.nativeUpdateValue(_:forKey:) (in Starscream) (:0)
WebSocket.WSResponse.__deallocating_deinit (in Starscream) (WebSocket.swift:0)
closure #2 in WebSocket.processResponse(_:) (in Starscream) (:0)
FoundationStream.cleanup() (in Starscream) (WebSocket.swift:249)
__NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 16
-[NSBlockOperation main] + 72
fassko commented 6 years ago

Hi @jincc !

Do you have any example app? That could help a ton to pinpoint this issue. Thanks!

jincc commented 6 years ago

I am re-opening and closing the socket when switching between the front and the back. Is this related?


- (void)didEnterBackground:(NSNotification *)_{
    if (self.status >= MTBLBCenterStatusConnecting) {
        [self close];
    }
}

- (void)didBecomeActive:(NSNotification *)_{
    if (self.status <= MTBLBCenterStatusDisconnected) {
        [self connect];
    }
}
jincc commented 6 years ago

@fassko

fassko commented 6 years ago

Try to connect again only if you disconnect from the socket. I think there can be a race condition.