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

Error upon socket connection closure #183

Open
roerohan opened this issue Nov 16, 2023 · 10 comments
Open

Error upon socket connection closure #183

roerohan opened this issue Nov 16, 2023 · 10 comments
Assignees
Labels
investigating legacy-releases These are issues for previous versions of the SDK not in active maintenance and support.

Comments

@roerohan
Copy link
Contributor

Description

I'm using v2.11.0 of your SDK and I often run into this error in live transcriptions.

future: <Task finished name='Task-311517' coro=<LiveTranscription._start() done, defined at /usr/local/lib/python3.11/dist-packages/deepgram/transcription.py:178> exception=ConnectionClosedError(Close(code=1011, reason='Deepgram did not provide a response message within the timeout window. See https://dpgr.am/net0000'), Close(code=1011, reason='Deepgram did not provide a response message within the timeout window. See https://dpgr.am/net0000'), True)>
 
Traceback (most recent call last):
 File "/usr/local/lib/python3.11/dist-packages/deepgram/transcription.py", line 222, in _start
   await self._socket.send(body)
 File "/usr/local/lib/python3.11/dist-packages/websockets/legacy/protocol.py", line 635, in send
   await self.ensure_open()
 File "/usr/local/lib/python3.11/dist-packages/websockets/legacy/protocol.py", line 939, in ensure_open
   raise self.connection_closed_exc()

After this, none of the send() method calls on an instance of the LiveTranscription object send any data over the socket.

Debugging

It seems like the issue is here:

if self._socket.closed:

It appears that the code only checks if the socket is closed when there is a message timeout while waiting in the queue.
However, if I insert a lot of messages in the queue (by calling the send method) when self._socket.closed is False, and the socket closes later, the code will try to send the message over a closed socket at some point, resulting in the above error.

Since there is no try except block, the error also causes the while loop to exit, and therefore I'm not able to send any more messages using that object.

@dvonthenen dvonthenen self-assigned this Nov 16, 2023
@jpvajda jpvajda added the bug Something isn't working label Nov 17, 2023
@jpvajda jpvajda added this to the Python SDK v3 Release milestone Nov 17, 2023
@dvonthenen
Copy link
Contributor

Hi @roerohan The Live client is in the process of getting a major overhaul. Will ping the community to take a look when the PR becomes available.

@roerohan
Copy link
Contributor Author

Alright!

I also wanted to bring to your notice that there's no way to handle this error currently since the async task created in the following code snippet isn't returned outside the SDK, and there's no way to catch the exception since I don't have access to this task

asyncio.create_task(self._start())

For now, the only way I found to fix it was a hacky workaround, by using the _socket object directly from the LiveTranscription class.

@dvonthenen
Copy link
Contributor

A new release was just posted which should address this problem, please take a look:
https://github.com/deepgram/deepgram-python-sdk/releases/tag/v3.0.0-alpha.1

@dvonthenen
Copy link
Contributor

Latest is alpha.4 with another release due out today

@dvonthenen
Copy link
Contributor

@roerohan alpha.5 is out and that commit is most likely going to be the beta.1 release. Have your y been able to try with this latest update?

@roerohan
Copy link
Contributor Author

roerohan commented Dec 3, 2023

Hi @dvonthenen
I'm currently using a workaround where I'm sending the socket messages directly using the _socket object. I'll try out the newer version as soon as I get some time.

@dvonthenen
Copy link
Contributor

cool. If you run into any problems, please let me know.

@dvonthenen
Copy link
Contributor

Re-opened to take a look at when I have time. I am unfamiliar with v2 version, so this might take some time.

@dvonthenen
Copy link
Contributor

@SandraRodgers said she would take a look at this issue and the other one since she has more knowledge about the v2 client.

@dvonthenen dvonthenen added legacy-releases These are issues for previous versions of the SDK not in active maintenance and support. investigating and removed bug Something isn't working labels Mar 26, 2024
@jz155
Copy link

jz155 commented Apr 26, 2024

i have an issue not sure if it is a similar one: Could not open socket: type object 'LiveTranscriptionEvents' has no attribute 'Unhandled'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigating legacy-releases These are issues for previous versions of the SDK not in active maintenance and support.
Projects
None yet
Development

No branches or pull requests

6 participants
@jpvajda @dvonthenen @roerohan @SandraRodgers @jz155 and others