Skip to content

Commit 0f70079

Browse files
committed
fix possible race condition
1 parent 750ba13 commit 0f70079

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

Source/SocketEngine.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,12 @@ public final class SocketEngine: NSObject, SocketEnginePollable, SocketEngineWeb
202202
postSendClose(nil, nil, nil)
203203
} else {
204204
// We need to take special care when we're polling that we send it ASAP
205-
postWait.append(String(SocketEnginePacketType.Close.rawValue))
206-
let req = createRequestForPostWithPostWait()
207-
doRequest(req, withCallback: postSendClose)
205+
// Also make sure we're on the emitQueue since we're touching postWait
206+
dispatch_sync(emitQueue) {
207+
self.postWait.append(String(SocketEnginePacketType.Close.rawValue))
208+
let req = self.createRequestForPostWithPostWait()
209+
self.doRequest(req, withCallback: postSendClose)
210+
}
208211
}
209212
}
210213

Source/SocketIOClient.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketParsable
214214
}
215215

216216
func didDisconnect(reason: String) {
217-
guard status != .Closed else {
218-
return
219-
}
217+
guard status != .Closed else { return }
220218

221219
DefaultSocketLogger.Logger.log("Disconnected: %@", type: logType, args: reason)
222220

0 commit comments

Comments
 (0)