Skip to content

Commit 998089d

Browse files
committed
Invalidate timer on reconnect failure
1 parent 283644b commit 998089d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

SocketIOClientSwift/SocketIOClient.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
139139
engine = SocketEngine(client: self, opts: opts)
140140
}
141141

142+
private func clearReconnectTimer() {
143+
reconnectTimer?.invalidate()
144+
reconnectTimer = nil
145+
}
146+
142147
/**
143148
Closes the socket. Only reopen the same socket if you know what you're doing.
144149
Will turn off automatic reconnects.
@@ -222,8 +227,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
222227
_connecting = false
223228
_reconnecting = false
224229
currentReconnectAttempt = 0
225-
reconnectTimer?.invalidate()
226-
reconnectTimer = nil
230+
clearReconnectTimer()
227231

228232
// Don't handle as internal because something crazy could happen where
229233
// we disconnect before it's handled
@@ -482,7 +486,9 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
482486
// We lost connection and should attempt to reestablish
483487
@objc private func tryReconnect() {
484488
if reconnectAttempts != -1 && currentReconnectAttempt + 1 > reconnectAttempts || !reconnects {
489+
clearReconnectTimer()
485490
didDisconnect("Reconnect Failed")
491+
486492
return
487493
} else if connected {
488494
_connecting = false

0 commit comments

Comments
 (0)