-
Notifications
You must be signed in to change notification settings - Fork 52
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
Bug: Concurrency issues when using FastAPI #101
Comments
I have the same issue when using FastAPI. I am also seeing an issue where a request to the database actually returns a previous query result causing serialization issues with my project. I haven't been able to recreate consistently but I imagine this is an issue related to socket polling happening out of order. It really makes this library unusable in production APIs at the moment. |
Same issue |
same issue.. when using within litestar, or plain python-service. |
As currently written, this library cannot handle concurrent queries over websocket. It expects the response for a command to follow immediately, in order. If you issue two commands before the first response, the responses may be out of order and this library will be confused. I've got a POC for a very simple asyncio wrapper around the websocket rpc. Tested on surrealdb 1.5.4 and 2.0.0 beta. It allows to send raw commands (use, signin, ...), perform queries and live queries. It only needs websockets and orjson (for speed, but could use standard json instead). see: https://gist.github.com/Anton-2/2f2919d402a95823a22d378455ec9ab3 Tell me if it works for you, I'll try to create a real library if there's enough interest. |
Yes. Interested
…On Mon, 9 Sep 2024 at 5:00 AM, Antonin ENFRUN ***@***.***> wrote:
As currently written, this library cannot handle concurrent queries over
websocket. It expects the response to a command to follow immediately, in
order. If you issue two commands before the first response, the responses
may be out of order and this library will be confused.
I've got a POC for a very simple asyncio wrapper around the websocket rpc.
Tested on surrealdb 1.5.4 and 2.0.0 beta.
It allows to send raw commands (use, signin, ...), perform queries and
live queries.
It only needs websockets <https://pypi.org/project/websockets/> and orjson
<https://pypi.org/project/orjson/> (for speed, but could use standard
json instead).
see: https://gist.github.com/Anton-2/2f2919d402a95823a22d378455ec9ab3
Tell me if it works for you, I'll try to create a real library if there's
enough interest.
—
Reply to this email directly, view it on GitHub
<#101 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABHR2QBAUSFVHVBNP6QUJRTZVTM2VAVCNFSM6AAAAABIRHI572VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMZWHA3DEMJVGE>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Feel free to try : surrealpy usage in FastAPI: db = SurrealDB()
@asynccontextmanager
async def lifespan(app: FastAPI):
await db.connect()
await db.signin({"user": "root", "pass": "root"})
await db.use("default", "default")
yield
await db.close()
app = FastAPI(lifespan=lifespan) |
So is there any official recommentation. This lib is presented
Maybe it woud be better to just open a PR to this repo with concurrency fixes. |
Describe the bug
When trying to use SurrealDB in a FastAPI project, whenever I get concurrent requests that hit the database, the application raises the following exception:
After that, the server becomes unresponsive and the only solution is to restart.
Steps to reproduce
Assuming you have docker installed:
git clone https://github.com/juangesino/surrealdb-fastapi-concurrency-error
cd surrealdb-fastapi-concurrency-error
make build
ordocker-compose -f docker-compose.yml up --build --force-recreate
make sequential
ordocker exec -it surreal-demo-server-1 python demo_sequential.py
make concurrent
ordocker exec -it surreal-demo-server-1 python demo_concurrent.py
You should get the exception mentioned before:
The server will not respond after that and you will have to restart it.
Expected behaviour
The Python SDK should be able to handle concurrent requests.
SurrealDB version
surrealdb/surrealdb:v1.5.0 (docker)
surrealdb.py version
0.3.2 for python:3.11.4-slim-buster (docker)
Contact Details
https://discord.com/channels/902568124350599239/1245739617525960778/1245768819553603666
Is there an existing issue for this?
Code of Conduct
The text was updated successfully, but these errors were encountered: