python-websocket-server icon indicating copy to clipboard operation
python-websocket-server copied to clipboard

Finishing of handle() after disconnect_clients_abruptly() leads to executing _client_left_ with None

Open vzarutskiy opened this issue 2 years ago • 0 comments

After executing disconnect_clients_abruptly() self.clients list is cleared.

    def _client_left_(self, handler):
        client = self.handler_to_client(handler)
        self.client_left(client, self)
        if client in self.clients:
            self.clients.remove(client)

Sometimes handle() function finished after this in point self.read_next_message():

    def handle(self):
        while self.keep_alive:
            if not self.handshake_done:
                self.handshake()
            elif self.valid_client:
                self.read_next_message()

It lead to execute finish() function with None client. Because handler_to_client() does not find client in self.client list:

    def handler_to_client(self, handler):
        for client in self.clients:
            if client['handler'] == handler:
                return client

vzarutskiy avatar Mar 22 '23 08:03 vzarutskiy