     private let operations = NSOperationQueue()
     private let socket: WebSocket
     private var isConnecting = false
+    private var isClosedByError = false
     private var retries = 0
     private var maxRetries = 2
 

                self.retries += 1
                self.connectWithToken()
            } else if let error = error {
                self.onError?(error)
            }
        }

                    return
                }
                guard let token = self.authStrategy.token else {
                    self.isClosedByError = true
                    let domain = "swift.WebSocketManager"
                    let description = "Could not obtain an authentication token."
                    let error = createError(domain, description: description)
