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

Getting an exeption when shutting down in threaded mode #104

Open
RoccoMarco opened this issue Aug 25, 2022 · 2 comments
Open

Getting an exeption when shutting down in threaded mode #104

RoccoMarco opened this issue Aug 25, 2022 · 2 comments

Comments

@RoccoMarco
Copy link

Hi,
I am getting an exception when I call shutdown_gracefully()

ERROR:websocket_server.websocket_server:********************************************************************************
Exception in child thread <WebsocketServerThread(Thread-162 (serve_forever), started daemon 25036)>: [WinError 10038] An operation was attempted on something that is not a socket


Looks like the issue is that the thread is still running when the websocket is closed and this triggers an operation of the closed socket

Any hint?

@RoccoMarco
Copy link
Author

I think the solution is to reorder the shout down functions and as good measure add a join

    def _shutdown_gracefully(self, status=CLOSE_STATUS_NORMAL, reason=DEFAULT_CLOSE_REASON):
        """
        Send a CLOSE handshake to all connected clients before terminating server
        """
        self.keep_alive = False
        self._disconnect_clients_gracefully(status, reason)
        self.shutdown()
        self.thread.join()
        self.server_close()


    def _shutdown_abruptly(self):
        """
        Terminate server without sending a CLOSE handshake
        """
        self.keep_alive = False
        self._disconnect_clients_abruptly()
        self.shutdown()
        self.thread.join()
        self.server_close()

@zpfz
Copy link

zpfz commented Oct 20, 2022

I think the solution is to reorder the shout down functions and as good measure add a join

    def _shutdown_gracefully(self, status=CLOSE_STATUS_NORMAL, reason=DEFAULT_CLOSE_REASON):
        """
        Send a CLOSE handshake to all connected clients before terminating server
        """
        self.keep_alive = False
        self._disconnect_clients_gracefully(status, reason)
        self.shutdown()
        self.thread.join()
        self.server_close()


    def _shutdown_abruptly(self):
        """
        Terminate server without sending a CLOSE handshake
        """
        self.keep_alive = False
        self._disconnect_clients_abruptly()
        self.shutdown()
        self.thread.join()
        self.server_close()

Hi, bro~it seems to test failed. But my console output :

ERROR:websocket_server.websocket_server:Invalid file descriptor: -1

have u the best way to solve this issue?

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

2 participants