Merge pull request #1034 from OneSman7/Fix-loosing-packets-on-websocket-connect-failure

Fixed loosing POST packets on web socket connection failure
This commit is contained in:
Erik Little 2018-06-07 06:47:04 -04:00 committed by GitHub
commit f7ccf338ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View File

@ -359,6 +359,7 @@ 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)
@ -371,6 +372,12 @@ 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)
if !postWait.isEmpty {
flushWaitingForPostToWebSocket()
}
}
private func flushProbeWait() {
@ -381,10 +388,6 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So
}
probeWait.removeAll(keepingCapacity: false)
if postWait.count != 0 {
flushWaitingForPostToWebSocket()
}
}
/// Causes any packets that were waiting for POSTing to be sent through the WebSocket. This happens because when

View File

@ -168,7 +168,11 @@ 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")
}
engine = SocketEngine(client: self, url: socketURL, config: config)