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

Bug: Can't use async concurrency with websocket connection. #164

Open
2 tasks done
Anton-2 opened this issue Feb 25, 2025 · 1 comment
Open
2 tasks done

Bug: Can't use async concurrency with websocket connection. #164

Anton-2 opened this issue Feb 25, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@Anton-2
Copy link

Anton-2 commented Feb 25, 2025

Describe the bug

When using AsyncSurreal with web socket (ws:// url), any attempt to have concurrent async requests fails with "cannot call recv while another coroutine is already running recv or recv_streaming".

This does not happen with the http client in v1.0.3.

Probably related to #101 and maybe #160 (async issues)

What is the status of this ? Should we use the http connection for async or is it a bug ? I remember the http connection having restrictions, and ws being the recommended way to use SurrealDB, so it seems strange to me.

#101 is closed with a message saying that concurrency issues are solved #101 (comment) but how can we "get 100% control over the async coroutine" ?

I really want to use SurrealDB, but for this async support in python should be rock solid.

Steps to reproduce

Here is a demo program (adapt for your auth, namespace and database)
Change the connection method (http to ws in AsyncSurreal("http://localhost:8000/rpc")) to go from working to failure.

import asyncio
from surrealdb import AsyncSurreal

async def main(n):
    async with AsyncSurreal("http://localhost:8000/rpc") as db:
        await db.signin({"username": 'root', "password": 'root'})
        await db.use("test", "test")
        async with asyncio.TaskGroup() as tg:
            tasks = [tg.create_task(db.query("select $p**2 as ret from {}", dict(p=num))) for num in range(n)]
    return [t.result()[0]["ret"] for t in tasks]

if __name__ == "__main__":
    print(asyncio.run(main(5)))

Expected behaviour

Working : (with http:) [0, 1, 4, 9, 16]
Not Working : (with ws:) websockets.exceptions.ConcurrencyError: cannot call recv while another coroutine is already running recv or recv_streaming

SurrealDB version

surreal version 2.2.1 for macos on aarch64

surrealdb.py version

surrealdb.py 1.0.3 for macOS on aarch64 using python 3.13.1

Contact Details

No response

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
@Anton-2 Anton-2 added the bug Something isn't working label Feb 25, 2025
@maxwellflitton
Copy link
Contributor

@Anton-2 thanks for the bug report, I'll run through this code example in a debugger to see what's going on. Currently working on a serialization of None error, then a RecordId check error but then after those this will be next.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants