Skip to content

Fixed loosing POST packets on web socket connection failure #1034

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

Merged
merged 2 commits into from
Jun 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions Source/SocketIO/Engine/SocketEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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() {
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Source/SocketIO/Manager/SocketManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down