Bug: websocket error in fastapi apps
coutouly opened this issue · 1 comments
coutouly commented
Describe the bug
i try to connect to surrealdb database through websocket, the connection works but the python app didn't receive the answer from database until websocket error (about 5 seconds)
Steps to reproduce
here is code python:
@router.post('/test/user')
async def get_user(request: Request):
start_time = time.time()
print(start_time)
user = "lucile.coutouly"
pas = "test"
async with Surreal("ws://surrealdb:8000/rpc") as db:
jeton = await db.signin({
'NS': 'test',
'DB': 'test',
'SC': 'account',
'user': user,
'pass': 'nancay'
})
print("---------------jeton")
end_time = time.time()
print(f"Time taken: {end_time - start_time} seconds")
and i get this from the two dockers:
archi-surrealdb-1 | 2023-08-04T13:04:19.029600Z INFO request: surreal::net::tracer: started processing request otel.kind="server" http.request.method="GET" url.path="/rpc" network.protocol.name="http" network.protocol.version="1.1" user_agent.original="Python/3.11 websockets/10.4" otel.name="GET /rpc" http.route="/rpc" http.request.id="19ecf533-a9cf-4ddd-8e48-38d709f5d39b" client.address="172.18.0.4"
archi-surrealdb-1 | 2023-08-04T13:04:19.029758Z INFO request: surreal::net::tracer: finished processing request otel.kind="server" http.request.method="GET" url.path="/rpc" network.protocol.name="http" network.protocol.version="1.1" user_agent.original="Python/3.11 websockets/10.4" otel.name="GET /rpc" http.route="/rpc" http.request.id="19ecf533-a9cf-4ddd-8e48-38d709f5d39b" client.address="172.18.0.4" http.response.body.size="0" http.response.status_code=101 http.latency.ms=0
archi-surrealdb-1 | 2023-08-04T13:04:19.030158Z TRACE surreal::net::rpc: WebSocket c8da133a-07c6-4a0e-a036-534ce62121cf connected
archi-surrealdb-1 | 2023-08-04T13:04:19.035981Z TRACE surreal::net::rpc: RPC Received: { id: '8cb81b92-b349-4e26-8aff-bc8204139c3e', method: 'signin', params: [{ DB: 'test', NS: 'test', SC: 'account', pass: 'nancay', user: 'lucile.coutouly' }] }
archi-surrealdb-1 | 2023-08-04T13:04:19.036283Z TRACE rpc signin:compute: surrealdb::dbs::iterator: Iterating: SELECT * FROM user WHERE user = $user AND crypto::argon2::compare(pass, $pass) websocket="c8da133a-07c6-4a0e-a036-534ce62121cf"
archi-surrealdb-1 | 2023-08-04T13:04:19.066350Z TRACE rpc response: surreal::rpc::res: Response sent response=Response { id: Some(Uuid(Uuid(8cb81b92-b349-4e26-8aff-bc8204139c3e))), result: Ok(Other(Strand(Strand("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpYXQiOjE2OTExNTQyNTksIm5iZiI6MTY5MTE1NDI1OSwiZXhwIjoxNjkxMjQwNjU5LCJpc3MiOiJTdXJyZWFsREIiLCJOUyI6InRlc3QiLCJEQiI6InRlc3QiLCJTQyI6ImFjY291bnQiLCJJRCI6InVzZXI64p-obHVjaWxlLmNvdXRvdWx54p-pIn0.2kxuTcDpMN06qYkdkzQfCuCxOaF2wTNh_IfNi-HMp2C_OJ2LL3PeOztgP0ZGP8EPRjthLoNtzok_BbBgr25elQ")))) }
archi-surrealdb-1 | 2023-08-04T13:04:19.067930Z TRACE surreal::net::rpc: WebSocket c8da133a-07c6-4a0e-a036-534ce62121cf disconnected
archi-surrealdb-1 | 2023-08-04T13:04:24.031213Z TRACE surreal::net::rpc: WebSocket error: Error { inner: ConnectionClosed }
archi-fastapi-1 | 1691154259.024649
archi-fastapi-1 | ---------------jeton
archi-fastapi-1 | ---------------role
archi-fastapi-1 | Time taken: 5.007425546646118 seconds
archi-fastapi-1 | INFO: 172.18.0.7:60342 - "POST /auth/test/user HTTP/1.1" 200 OK
archi-surrealdb-1 | 2023-08-04T13:04:24.286890Z TRACE surreal::net::rpc: RPC Received: { method: 'ping' }
archi-surrealdb-1 | 2023-08-04T13:04:24.286943Z TRACE rpc response: surreal::rpc::res: Response sent response=Response { id: None, result: Ok(Other(None)) }
Expected behaviour
the response should be instantaneted.
SurrealDB version
nightly on docker
surrealdb.py version
last
Contact Details
Is there an existing issue for this?
- I have searched the existing issues
Code of Conduct
- I agree to follow this project's Code of Conduct
coutouly commented
it seems like with the new nightly build there is no deconnexion code and that it's fast answer
thanks for the work