Skip to content

_terminate_client_handlers does not close all clients #116

@vzarutskiy

Description

@vzarutskiy

_terminate_client_handlers uses "for" cycle for clients disconnecting:

for client in self.clients:
            self._terminate_client_handler(client["handler"])

It executes client_left as finish(), there client is removed form self.clients list. It leads to an index shift and second client in list will be not disconnected.
For example:

 def stop_server(self):
        print("before disconnect")
        print(self.server.clients)
        self.server.disconnect_clients_abruptly()
        print(self.server.clients)
        print("after disconnect")

Result:
before disconnect

[{'id': 1, 'handler': <__main__.WSWithBinary object at 0x7ff85472c370>, 'address': ('192.168.23.143', 54582)}, {'id': 2, 'handler': <__main__.WSWithBinary object at 0x7ff8547f0a60>, 'address': ('192.168.23.143', 54584)}]
Client(1) disconnected
[{'id': 2, 'handler': <__main__.WSWithBinary object at 0x7ff8547f0a60>, 'address': ('192.168.23.143', 54584)}]
after disconnect

Possible fix:

    def _terminate_client_handlers(self):
        clients_list = self.clients.copy()
        for client in clients_list:
            self._terminate_client_handler(client["handler"])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions