Duplicate websocket messages
See original GitHub issue- Your OS and runtime environment, and browser if applicable
Browser: chrome, OS: ubuntu
- The versions of Channels, Daphne, Django, Twisted, and your ASGI backend (asgi_ipc or asgi_redis normally)
asgi-redis==1.4.3 channels==1.1.8 Django==1.10.4 Twisted==16.6.0
- What you expected to happen vs. what actually happened
I am receiving duplicate messages in my consumer. I have a java client that stays connected and attempts to reconnect at all times to the websocket. I also have web clients sending messages to websocket to a dedicated channels group just for them, which is then resent to a dedicated channels group for the java process. Especially if I restart daphne, runworker and celery a lot, I receive duplicate messages (or triplicate, or nplicate, you get the idea) from my web clients. I have verified that the messages are not sent twice by the clients. Note that I’ve logged the duplicate messages in python (def ws_message(message)), not just in my java process, which consequently also receives duplicates. Once I start to receive duplicates I have to restart the processes, and then it’s ok until I restart it again. It seems rather random, the fact if I do or do not get duplicates within a lifecycle of the channels app, but the issue is never resolved without a restart. I receive n-plicates from all my clients, which are many.
- How you’re running Channels (runserver? daphne/runworker? Nginx/Apache in front?)
I’m running it behind nginx with daphne & runworker.
- Console logs and full tracebacks of any errors
No errors really, just duplicates.
This is how I’m logging my duplicates:
channel_routing = [
route("websocket.connect", ws_add),
route("websocket.receive", ws_message),
route("websocket.disconnect", ws_disconnect),
]
def ws_add(message):
room = re.sub("/websocket/", '', message.content['path'])
message.reply_channel.send({"accept": True})
Group(str(room)).add(message.reply_channel)
def ws_message(message):
room = re.sub("/websocket/", '', message.content['path'])
text = message.content['text']
txt = json.loads(text)
print(txt)
def ws_disconnect(message):
Group("java").discard(message.reply_channel)
Group("web").discard(message.reply_channel)
I am using reconnecting-websocket (https://github.com/joewalnes/reconnecting-websocket) to connect to it via frontend.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (4 by maintainers)
Channels 2 is released, closing this as the transport is now not over a network and so this won’t happen.
@bkovacev Hard deadlines are not something a volunteer project has, but it should be more like 2 months than 6.