Skip to content

Redis integration is broken. #197

@Skycoder42

Description

@Skycoder42

Hi,

there are various issues with the current redis implementation. I suspect it has to do with updates of asyncio, but I cannot say for certain. I was able to identify two problems:


This first error is as follows:

  File "/usr/local/lib/python3.12/asyncio/tasks.py", line 461, in wait
    raise TypeError("Passing coroutines is forbidden, use tasks explicitly.")

This seems to happen because the call to handle_message (See https://github.com/etesync/server/blob/master/etebase_server/fastapi/routers/websocket.py#L132) is not wrapped in a task:

        try:
            while True:
                # We wait on the websocket so we fail if web sockets fail or get data
                receive = asyncio.create_task(websocket.receive())  # <=== this is correct
                done, pending = await asyncio.wait(
                    {receive, handle_message()},  # <=== but is missing for handle_message
                    return_when=asyncio.FIRST_COMPLETED,
                )
                for task in pending:
                    task.cancel()
                if receive in done:
                    # Web socket should never receive any data
                    await websocket.close(code=status.WS_1008_POLICY_VIOLATION)
                    return

After fixing that, a second error appears:

File "/etebase/etebase_server/fastapi/routers/websocket.py", line 124, in handle_message
_, message = message_raw
^^^^^^^^^^
ValueError: too many values to unpack (expected 2)

This seems to have to do with the fact, that pubsub.get_message does not return a tuple, but a dict (See https://aredis.readthedocs.io/en/latest/pubsub.html). When casting it to a tuple (See https://github.com/etesync/server/blob/master/etebase_server/fastapi/routers/websocket.py#L122), it fails:

        async def handle_message():
            msg = await pubsub.get_message(ignore_subscribe_messages=True, timeout=20)
            message_raw = t.cast(t.Optional[t.Tuple[str, bytes]], msg) # <=== should instead be treated as map
            if message_raw:
                _, message = message_raw  # <=== access via data
                await ws.send_bytes(message)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions