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

Crash in redis/asyncio/connection.py using Django Channels #395

Open
developcreativo opened this issue Jul 26, 2024 · 1 comment
Open

Crash in redis/asyncio/connection.py using Django Channels #395

developcreativo opened this issue Jul 26, 2024 · 1 comment

Comments

@developcreativo
Copy link

I'm encountering an issue when using Redis with Django Channels, where the connection crashes. Below are the details of my setup and an example of the code that's causing the issue:

Environment:

  • Python version: 3.11.7
  • Django version: 5.0.3
  • Channels version: 4.1.0
  • Channels Redis version: 4.2.0
  • Redis version: 5.4.0
  • Operating System: Ubuntu 20.04

Code Example:

from channels.generic.websocket import AsyncWebsocketConsumer

class ChatConsumer(AsyncWebsocketConsumer):
    channel_layer_alias = "chat"

    async def connect(self):
        user = self.scope["user"]
        if user.is_authenticated:
            # Accept the connection
            await self.accept()
            # Add the channel to a group with the current user's id
            await self.channel_layer.group_add(str(user.id), self.channel_name)

            on_websocket_connect_task.apply_async(
                kwargs=dict(channel_name=self.channel_name, user_id=str(user.id)),
                queue=settings.QUEUE_CHAT,
            )
        else:
            self.close(code=1000)

Error:
The connection crashes in redis/asyncio/connection.py. Here is the traceback:

image

This error occurs repeatedly when the socket remains inactive for hours. It happens not only in the chat application but also in others. To connect to a socket, we have to attempt to connect up to 3 times.

@bigfootjon
Copy link
Collaborator

I don't see a traceback (just an error message), do you have any further information about where the exception is being raised?

Do you have a minimal repro? I.e. do you have some self-contained code that I could run and see this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants