The notifyDelegateDidFlushOutput function checks if the delegate
responds to the webSocketDidFlushOutput: selector before sending it.
The only possible cause for the crash is when the delegate changes
between the check and the call because the function is not atomic. Added
testChangingDelegateWhileFlushingOutputShouldNotCrashWithUnrecognizedSelector
can reproduce the crash very quickly and consistently.
The fix here is to capture the delegate strongly while the function is
running to work with the same instance. The patch fixes the crash in all
similar places in PSWebSocket, as well as in PSWebSocketServer.
An app using
PocketSocket
crashes occasionally with this information:The
notifyDelegateDidFlushOutput
function checks if the delegate responds to thewebSocketDidFlushOutput:
selector before sending it. The only possible cause for the crash is when the delegate changes between the check and the call because the function is not atomic. AddedtestChangingDelegateWhileFlushingOutputShouldNotCrashWithUnrecognizedSelector
can reproduce the crash very quickly and consistently.The fix here is to capture the delegate strongly while the function is running to work with the same instance. The patch fixes the crash in all similar places in
PSWebSocket
, as well as inPSWebSocketServer
.