question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
andrewgodwincommented, Feb 2, 2018

Channels 2 is released, closing this as the transport is now not over a network and so this won’t happen.

0reactions
andrewgodwincommented, Dec 20, 2017

@bkovacev Hard deadlines are not something a volunteer project has, but it should be more like 2 months than 6.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node.js Websocket chat app: clients receiving duplicate ...
I am new to Node.js. I am trying to implement a chat app using Node.js, websocket. The code I have used on the...
Read more >
Websocket stability handling and duplicate sockets
Hi Folks, working to build a robust system to auto-reconnect in the event of socket drop. I'm taking advantage of app.SetOnError, ws.onclose, and...
Read more >
Duplicate websocket messages. · Issue #427 - GitHub
My channel listen query is here. when i chat with more than one person. using websockets it shows duplicate messages on receiver side....
Read more >
Receiving duplicate update messages with Webscoket - Forum
I can replicate the issue with ADS 3.2. 1 and your JSON request message. The application receives duplicate update messages.
Read more >
1673340 - WebSocket duplicate packets sent - Bugzilla@Mozilla
Packets shouldn't be sent duplicated. When using Firefox 81.0.2 (or the latest Chrome/Edge/Vivaldi and Safari), all packets are sent only once and everything ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found