Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_terminate_client_handlers does not close all clients #116

Open
vzarutskiy opened this issue Mar 15, 2023 · 0 comments
Open

_terminate_client_handlers does not close all clients #116

vzarutskiy opened this issue Mar 15, 2023 · 0 comments

Comments

@vzarutskiy
Copy link

_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"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant