Closed roerohan closed 2 months ago
Ooooh very nice catch!
This needs to also be done for the sync client here, if you can add that would be great: https://github.com/deepgram/deepgram-python-sdk/blob/main/deepgram/clients/live/v1/client.py#L476
If you could replace this exception handling with this to provide more detail on the error, that would be great as well:
except websockets.exceptions.ConnectionClosedOK as e:
self.logger.notice(f"_signal_exit - connection closed: {e.code}")
except websockets.exceptions.WebSocketException as e:
self.logger.error("_signal_exit - WebSocketException: {str(e)}")
except Exception as e:
self.logger.error("_signal_exit - Exception: {str(e)}")
Thanks for finding this issue!
@dvonthenen thanks for the swift response!
I've updated the PR, please take a look and let me know if I should make any other changes too.
This looks great! I appreciate finding and fixing this issue!
Proposed changes
In the
_listening
function, when there's aWebSocketException
, the following line runs as a part of the error handling procedure.https://github.com/deepgram/deepgram-python-sdk/blob/d2c43344e723df99468bff161e5e2a1c29600fd8/deepgram/clients/live/v1/async_client.py#L371
Now, the
WebSocketException
might also be caused due to the socket connection breaking. In this case, an error is thrown of the following formWhile handling this exception, the
_signal_exit
function is called, which has the following lines https://github.com/deepgram/deepgram-python-sdk/blob/d2c43344e723df99468bff161e5e2a1c29600fd8/deepgram/clients/live/v1/async_client.py#L483-L496In line 488, we're doing a
self._socket.send
, which is bound to fail because the socket connection is closed. This throws an error from the_signal_exit
method. Since_signal_exit
is not wrapped in atry except
, the_listening
method also throws an error and exits. The following is a sample traceback.In this PR, I've added a
try except
only around theself._socket.send
. It might be necessary to add exception handling wherever_signal_exit
is being called as well, as when_signal_exit
throws an error, thewhile True
loop will exit, and thelisten_thread
will not exist anymore. Therefore any transcripts will not be received for that connection.Closes #356
Types of changes
What types of changes does your code introduce to the community Python SDK? Put an
x
in the boxes that applyChecklist
Put an
x
in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.Further comments