Open immohsin opened 5 years ago
Interesting. Can you show the source for your read()
function?
@elprans Here is the read function.
async def read(id: str, env)
query = '''SELECT app_value FROM table_name WHERE id=$1;'''.
connection = await asyncpg.connect(**creds)
try:
app = await connection.fetchval(query, id))
finally:
await connection.close()
if not app and env is 'stage':
app = await self.read(id, 'prod')
return app
@elprans any idea why its occurring during closing the connection object?
It looks like a race. The protocol handler is receiving data from the server while not expecting anything. Is finally
called normally or is there a preceding exception?
finally
is getting called normally there is no exception.
The way I have handled now is to catch for InternalClientError exception while closing the connection.
A similar error happens in my case, but a connection is closed by a CancelledError exception inside a context manager and I got
InternalClientError: got result for unknown protocol state 3
I'm also getting InternalClientError: got result for unknown protocol state 3
:
asyncpg version: 0.29.0 PostgreSQL version: 9.5.10 Do you use a PostgreSQL SaaS? If so, which? GCP PostgreSQL Python version: 3.11.9 Platform: linux Do you use pgbouncer?: Yes Did you install asyncpg with pip?: Yes
Got this error after a long time of running app:
File "/usr/local/lib/python3.11/site-packages/databases/core.py", line 152, in fetch_one
return await connection.fetch_one(query, values)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/databases/core.py", line 269, in fetch_one
return await self._connection.fetch_one(built_query)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/databases/backends/postgres.py", line 189, in fetch_one
row = await self._connection.fetchrow(query_str, *args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/asyncpg/connection.py", line 749, in fetchrow
data = await self._execute(
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/asyncpg/connection.py", line 1794, in _execute
result, _ = await self.__execute(
^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/asyncpg/connection.py", line 1892, in __execute
result, stmt = await self._do_execute(
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/asyncpg/connection.py", line 1925, in _do_execute
stmt = await self._get_statement(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/asyncpg/connection.py", line 433, in _get_statement
statement = await self._protocol.prepare(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "asyncpg/protocol/protocol.pyx", line 166, in prepare
File "asyncpg/protocol/protocol.pyx", line 902, in asyncpg.protocol.protocol.BaseProtocol._dispatch_result
asyncpg.exceptions._base.InternalClientError: got result for unknown protocol state 3
asyncpg version: 0.18.1 PostgreSQL version: 9.5.10 Do you use a PostgreSQL SaaS? If so, which? Can you reproduce the issue with a local PostgreSQL install?: using google cloud sql pg instance Python version: 3.6.5 Platform: Ubuntu Do you use pgbouncer?: No Did you install asyncpg with pip?: Yes If you built asyncpg locally, which version of Cython did you use?: Can the issue be reproduced under both asyncio and uvloop?: No
I have been facing this error for quite sometime intermittently
asyncpg.exceptions._base.InternalClientError: got result for unknown protocol state 0
The entire stack trace:
Can someone explain when this exception is thrown and for what reason? If i know the reason this exception is thrown, i can figure out the issue myself. I'm not able to reproduce locally or in my stage environment.