edgedb-python: getting ClientConnectionClosedError randomly
I am connecting to EdgeDB-SERVER in a GCP VM, using FASTAPI, code is given below API code file and edgedb.toml are already in the same directory.
conn = edgedb.connect()
@app.post("/add_data")
def add_data(data : Item):
logging.info(f"Connection_is_closed() : {conn.is_closed()}")
if conn.is_closed():
conn._reconnect()
if conn:
return conn.query_json("some query here..")
Whenever I send a request got my response but randomly get ClientConnectionClosedError.
just before and after the error
- request sent, got an error
INFO:root:Connection_is_closed() : False
INFO: IP:55358 - "POST /add_batch_data_uc HTTP/1.1" 500 Internal Server Error
ERROR: Exception in ASGI application
Traceback (most recent call last): LONG ERROR BELOW
- when I resent/retry the request, got my response, no error
INFO:root:Connection_is_closed() : True
INFO:root:Query exec time: 0:00:00.013752
INFO: IP:55366 - "POST /add_batch_data_uc HTTP/1.1" 200 OK
INFO:root:Connection_is_closed() : False
INFO:root:Query exec time: 0:00:00.014205
INFO: IP:55366 - "POST /add_batch_data_uc HTTP/1.1" 200 OK
- same problem happens randomly when I try to execute
conn.json(query)in random_test.ipynb. It works most of the time but sometimes I got ClientConnectionClosedError
import asyncio
import datetime
import edgedb
conn= edgedb.connect()
conn.query_json( a query inside ) # generates error randomly / rarely
- ERROR
INFO:root:Connection_is_closed() : False
INFO:root:query_execution_time : 0:00:00.015267
INFO: IP_address:54516 - "POST /add_batch_data_uc HTTP/1.1" 200 OK
INFO:root:Connection_is_closed() : False
INFO: IP_address:24256 - "POST /add_batch_data_uc HTTP/1.1" 500 Internal Server Error
ERROR: Exception in ASGI application
Traceback (most recent call last):
ERROR:uvicorn.error:Exception in ASGI application
Traceback (most recent call last):
File "/home/user/.local/lib/python3.8/site-packages/uvicorn/protocols/http/httptools_impl.py", line 376, in run_asgi
result = await app(self.scope, self.receive, self.send)
File "/home/user/.local/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 75, in __call__
return await self.app(scope, receive, send)
File "/home/user/.local/lib/python3.8/site-packages/fastapi/applications.py", line 208, in __call__
await super().__call__(scope, receive, send)
File "/home/user/.local/lib/python3.8/site-packages/starlette/applications.py", line 112, in __call__
await self.middleware_stack(scope, receive, send)
File "/home/user/.local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 181, in __call__
raise exc
File "/home/user/.local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 159, in __call__
await self.app(scope, receive, _send)
File "/home/user/.local/lib/python3.8/site-packages/starlette/exceptions.py", line 82, in __call__
raise exc
File "/home/user/.local/lib/python3.8/site-packages/starlette/exceptions.py", line 71, in __call__
await self.app(scope, receive, sender)
File "/home/user/.local/lib/python3.8/site-packages/starlette/routing.py", line 656, in __call__
await route.handle(scope, receive, send)
File "/home/user/.local/lib/python3.8/site-packages/starlette/routing.py", line 259, in handle
await self.app(scope, receive, send)
File "/home/user/.local/lib/python3.8/site-packages/starlette/routing.py", line 61, in app
response = await func(request)
File "/home/user/.local/lib/python3.8/site-packages/fastapi/routing.py", line 226, in app
raw_response = await run_endpoint_function(
File "/home/user/.local/lib/python3.8/site-packages/fastapi/routing.py", line 161, in run_endpoint_function
return await run_in_threadpool(dependant.call, **values)
File "/home/user/.local/lib/python3.8/site-packages/starlette/concurrency.py", line 39, in run_in_threadpool
return await anyio.to_thread.run_sync(func, *args)
File "/home/user/.local/lib/python3.8/site-packages/anyio/to_thread.py", line 28, in run_sync
return await get_asynclib().run_sync_in_worker_thread(func, *args, cancellable=cancellable,
File "/home/user/.local/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 818, in run_sync_in_worker_thread
return await future
File "/home/user/.local/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 754, in run
result = context.run(func, *args)
File "main.py", line 106, in add_batch_data
var = (conn.query_json('''INSERT uniform_comp {
File "/home/user/.local/lib/python3.8/site-packages/edgedb/blocking_con.py", line 379, in query_json
return self._execute(
File "/home/user/.local/lib/python3.8/site-packages/edgedb/blocking_con.py", line 342, in _execute
raise e
File "/home/user/.local/lib/python3.8/site-packages/edgedb/blocking_con.py", line 314, in _execute
return self._get_protocol().sync_execute_anonymous(
File "edgedb/protocol/blocking_proto.pyx", line 105, in edgedb.protocol.blocking_proto.BlockingIOProtocol.sync_execute_anonymous
File "edgedb/protocol/blocking_proto.pyx", line 91, in edgedb.protocol.blocking_proto.BlockingIOProtocol._iter_coroutine
File "edgedb/protocol/protocol.pyx", line 677, in execute_anonymous
File "edgedb/protocol/protocol.pyx", line 474, in _optimistic_execute
File "edgedb/protocol/blocking_proto.pyx", line 62, in wait_for_message
edgedb.errors.ClientConnectionClosedError
INFO:root:Connection_is_closed() : True
INFO:root:query_execution_time : 0:00:00.017633
INFO: IP_address:54530 - "POST /add_batch_data_uc HTTP/1.1" 200 OK
INFO:root:Connection_is_closed() : False
INFO:root:query_execution_time : 0:00:00.014480
INFO: IP_address:54530 - "POST /add_batch_data_uc HTTP/1.1" 200 OK
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 1
- Comments: 15 (8 by maintainers)
@monomonedula Sorry it was just moved to: https://www.edgedb.com/docs/reference/http#observability