fix: handle socket connection closed error in _signal_exit #355
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed changes
In the
_listening
function, when there's aWebSocketException
, the following line runs as a part of the error handling procedure.deepgram-python-sdk/deepgram/clients/live/v1/async_client.py
Line 371 in d2c4334
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 linesdeepgram-python-sdk/deepgram/clients/live/v1/async_client.py
Lines 483 to 496 in d2c4334
In 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