You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my project, I want a message to be sent to a group when a client connects or disconnects. The "listener" of that group is a different consumer.
To detect connections, I group_send in the connect method.
To detect disconnections, I group_send in the disconnect method.
Events sent in connect work perfectly, and are always received. Events sent in disconnect however are very inconsistent and not received every time.
I've narrowed down the issue and have determined that it only occurs when using the channels_redis.core.RedisChannelLayer channel layer. channels.layers.InMemoryChannelLayer and channels_redis.pubsub.RedisPubSubChannelLayer work perfectly.
This demo has a chat and a user log on a web page. The chat functionality uses the first consumer. When a user connects or disconnects, this information is printed to the chat log. When a user sends a message, it is printed to the chat log. The user log only shows connections and disconnections, but no chat messages. The user log connects to a second consumer. When a user connects or disconnects, their consumer additionally sends a group message to the user log consumer.
If you open multiple tabs of the demo page, and then close them one by one, you can observe in a different window that disconnections are always recorded in the chat log, but they are inconsistently recorded in the user log. The correct behavior would be for all disconnections to be logged in both places.
Steps to Reproduce
Clone the repo
Create a virtual environment
Install the dependencies in requirements.txt
Start the server with python manage.py runserver
Open a web browser to 127.0.0.1:8000
Duplicate the tab so that you have around 10 - 15 total instances of the web page
While viewing one of the tabs consistently, start closing tabs one by one. Observe that the disconnection message for each always appears in the chat log, but they inconsistently appear in the user log.
In redis_channel_layer_bug/settings.py, I have commented some other CHANNEL_LAYER configurations. The only one this issue is observed with is channels_redis.core.RedisChannelLayer.
Prior to creating this demo, I experimented with having a single ChatConsumer. ChatConsumers join the "chat" group on connect, and leave the "chat" group on disconnect. ChatConsumers group_send to the "chat" group on connect, and group_send to the "chat" group on disconnect. This appeared to always work correctly. I believe this means that the issue specifically relates to communication between different consumers.
In my project, I want a message to be sent to a group when a client connects or disconnects. The "listener" of that group is a different consumer.
To detect connections, I group_send in the
connect
method.To detect disconnections, I group_send in the
disconnect
method.Events sent in
connect
work perfectly, and are always received. Events sent indisconnect
however are very inconsistent and not received every time.I've narrowed down the issue and have determined that it only occurs when using the
channels_redis.core.RedisChannelLayer
channel layer.channels.layers.InMemoryChannelLayer
andchannels_redis.pubsub.RedisPubSubChannelLayer
work perfectly.I reproduced the issue in this demo repo: https://github.com/agsimmons/redis-channel-layer-bug
This demo has a chat and a user log on a web page. The chat functionality uses the first consumer. When a user connects or disconnects, this information is printed to the chat log. When a user sends a message, it is printed to the chat log. The user log only shows connections and disconnections, but no chat messages. The user log connects to a second consumer. When a user connects or disconnects, their consumer additionally sends a group message to the user log consumer.
If you open multiple tabs of the demo page, and then close them one by one, you can observe in a different window that disconnections are always recorded in the chat log, but they are inconsistently recorded in the user log. The correct behavior would be for all disconnections to be logged in both places.
Steps to Reproduce
requirements.txt
python manage.py runserver
127.0.0.1:8000
In
redis_channel_layer_bug/settings.py
, I have commented some other CHANNEL_LAYER configurations. The only one this issue is observed with ischannels_redis.core.RedisChannelLayer
.Prior to creating this demo, I experimented with having a single ChatConsumer. ChatConsumers join the "chat" group on connect, and leave the "chat" group on disconnect. ChatConsumers group_send to the "chat" group on connect, and group_send to the "chat" group on disconnect. This appeared to always work correctly. I believe this means that the issue specifically relates to communication between different consumers.
OS: Arch Linux
ASGI Server: daphne
The text was updated successfully, but these errors were encountered: