Skip to content

Commit

Permalink
fix(websockets): update socket error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
janaab11 committed Jan 3, 2025
1 parent 16dbbc0 commit dd1ff48
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/diart/websockets.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import socket
from dataclasses import dataclass
from pathlib import Path
from typing import Any, AnyStr, Callable, Dict, Optional, Text, Union
Expand Down Expand Up @@ -174,7 +173,7 @@ def _on_connect(self, client: Dict[Text, Any], server: WebsocketServer) -> None:

# Send ready notification to client
self.send(client_id, "READY")
except (socket.error, ConnectionError) as e:
except OSError as e:
logger.warning(f"Client {client_id} connection failed: {e}")
# Just cleanup since client is already disconnected
self.close(client_id)
Expand Down Expand Up @@ -223,7 +222,7 @@ def _on_message_received(
# decode message to audio
decoded_audio = utils.decode_audio(message)
self._clients[client_id].audio_source.process_message(decoded_audio)
except (socket.error, ConnectionError) as e:
except OSError as e:
logger.warning(f"Client {client_id} disconnected: {e}")
# Just cleanup since client is already disconnected
self.close(client_id)
Expand Down Expand Up @@ -308,7 +307,7 @@ def run(self) -> None:
try:
self.server.run_forever()
break # If server exits normally, break the retry loop
except (socket.error, ConnectionError) as e:
except OSError as e:
logger.warning(f"WebSocket server connection error: {e}")
retry_count += 1
if retry_count < max_retries:
Expand Down

0 comments on commit dd1ff48

Please sign in to comment.