From 5fdff65281ae9ff61c81e76a20b268494edc96f3 Mon Sep 17 00:00:00 2001 From: Erik Little Date: Thu, 7 Jun 2018 07:15:43 -0400 Subject: [PATCH] Clarify comments to explain why we did the move --- Source/SocketIO/Engine/SocketEngine.swift | 6 +++--- Source/SocketIO/Manager/SocketManager.swift | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Source/SocketIO/Engine/SocketEngine.swift b/Source/SocketIO/Engine/SocketEngine.swift index bca0944..a1a80a1 100644 --- a/Source/SocketIO/Engine/SocketEngine.swift +++ b/Source/SocketIO/Engine/SocketEngine.swift @@ -359,7 +359,6 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So /// /// **You shouldn't call this directly** open func doFastUpgrade() { - if waitingForPoll { DefaultSocketLogger.Logger.error("Outstanding poll when switched to WebSockets," + "we'll probably disconnect soon. You should report this.", type: SocketEngine.logType) @@ -372,9 +371,10 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So fastUpgrade = false probing = false flushProbeWait() - + // Need to flush postWait to socket since it connected successfully - // (moved from flushProbeWait() since it is also called on connected failure) + // moved from flushProbeWait() since it is also called on connected failure, and we don't want to try and send + // packets through WebSockets when WebSockets has failed! if !postWait.isEmpty { flushWaitingForPostToWebSocket() } diff --git a/Source/SocketIO/Manager/SocketManager.swift b/Source/SocketIO/Manager/SocketManager.swift index 830bf93..cf88240 100644 --- a/Source/SocketIO/Manager/SocketManager.swift +++ b/Source/SocketIO/Manager/SocketManager.swift @@ -168,9 +168,8 @@ open class SocketManager : NSObject, SocketManagerSpec, SocketParsable, SocketDa DefaultSocketLogger.Logger.log("Adding engine", type: SocketManager.logType) engine?.engineQueue.sync { - self.engine?.client = nil - + // Close old engine so it will not leak because of URLSession if in polling mode self.engine?.disconnect(reason: "Adding new engine") }