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

Trigger WSClient Disconnect When WS Connection Closed #480

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion deepgram/clients/common/v1/abstract_async_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,18 @@ async def _listening(self) -> None:
self._logger.debug("AbstractAsyncWebSocketClient._listening LEAVE")

except websockets.exceptions.ConnectionClosedOK as e:
# signal exit and close
await self._signal_exit()

self._logger.notice(f"_listening({e.code}) exiting gracefully")
self._logger.debug("AbstractAsyncWebSocketClient._listening LEAVE")
return

except websockets.exceptions.ConnectionClosed as e:
if e.code in [1000, 1001]:
# signal exit and close
await self._signal_exit()

self._logger.notice(f"_listening({e.code}) exiting gracefully")
self._logger.debug("AbstractAsyncWebSocketClient._listening LEAVE")
return
Expand Down Expand Up @@ -466,7 +472,7 @@ async def finish(self) -> bool:
except asyncio.CancelledError as e:
self._logger.error("tasks cancelled error: %s", e)
self._logger.debug("AbstractAsyncWebSocketClient.finish LEAVE")
return False
return True

async def _signal_exit(self) -> None:
# send close event
Expand Down
6 changes: 6 additions & 0 deletions deepgram/clients/common/v1/abstract_sync_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,18 @@ def _listening(
self._logger.debug("AbstractSyncWebSocketClient._listening LEAVE")

except websockets.exceptions.ConnectionClosedOK as e:
# signal exit and close
self._signal_exit()

self._logger.notice(f"_listening({e.code}) exiting gracefully")
self._logger.debug("AbstractSyncWebSocketClient._listening LEAVE")
return

except websockets.exceptions.ConnectionClosed as e:
if e.code in [1000, 1001]:
# signal exit and close
self._signal_exit()

self._logger.notice(f"_listening({e.code}) exiting gracefully")
self._logger.debug("AbstractSyncWebSocketClient._listening LEAVE")
return
Expand Down
Loading