Skip to content

Commit

Permalink
Fix closing not actually closing / giving exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
sheepy0125 committed Aug 10, 2022
1 parent 3a6ca2a commit d2491bb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 5 additions & 1 deletion hisock/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,11 @@ def close(self, emit_leave: bool = True):
self._send_raw("$USRCLOSE$")
except OSError: # Server already closed socket
return
# self.sock.shutdown(socket.SHUT_RDWR) DEBUG
try:
self.sock.shutdown(socket.SHUT_RDWR)
except OSError:
# Bad file descriptor
...
self.sock.close()

# Main loop
Expand Down
12 changes: 10 additions & 2 deletions hisock/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,11 @@ def close(self):
self.closed = True
self._keepalive_event.set()
self.disconnect_all_clients()
self.socket.shutdown(socket.SHUT_RDWR)
try:
self.socket.shutdown(socket.SHUT_RDWR)
except OSError:
# Bad file descriptor
...
self.socket.close()

# Main loop
Expand Down Expand Up @@ -1158,7 +1162,11 @@ def close(self):

super().close()
self._stop_event.set()
self._thread.join()
try:
self._thread.join()
except RuntimeError:
# Cannot join current thread
return

def start(self, callback: Callable = None, error_handler: Callable = None):
"""
Expand Down

0 comments on commit d2491bb

Please sign in to comment.