         request.applyDefaultMessageSocketSetting()
         let socket = WebSocket(request: request)
         resetTimeShiftVariables()
-        socket.onEvent = { [weak self] in
-            self?.handleTimeShiftMessageSocketEvent(
+        socket.onEvent = { [weak self, weak socket] in
+            guard let me = self, let socket = socket else { return }
+            me.handleTimeShiftMessageSocketEvent(
                 socket: socket,
                 event: $0,
                 userId: userId,

        stopAllTimers()

        [watchSocket, messageSocket].forEach {
            // Do not call `$0?.onEvent = nil` here.
            // I'm not sure the reason but, for sure, letting the `onEvent` to be nil
            // before calling `$0?.disconnect()` makes the network connections not
            // being cleaned-up with the states like `CloseWait`. And they are
            // piled-up and eventually causes network error for new connection request
            // with the message like “No space left on device”.
            // You can confirm this "memory leak" in Network Activity Report in Xcode.
            $0?.disconnect()
        }
        watchSocket = nil
        messageSocket = nil

        live = nil
        isConnected = false

        var request = URLRequest(url: webSocketUrl)
        request.applyDefaultWatchSocketSetting()
        let socket = WebSocket(request: request)
        socket.onEvent = { [weak self, weak socket] in
            guard let me = self, let socket = socket else { return }
            me.handleWatchSocketEvent(
                socket: socket,
                event: $0,
                completion: completion)
