0

hello I am working on chatting app with django channels works perfectly in localhost but once I used redis and deployed to heroku I can't send anymessage the websocket always close, my settings.py

CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "channels_redis.core.RedisChannelLayer",
        "CONFIG": {
            "hosts": [os.environ.get('REDIS_URL', 'redis://localhost:6379')],
        },
    },
}

I am using redis and postgresql addons, and my Procfile is like this

web: daphne myproject.asgi:application --port $PORT --bind 0.0.0.0 -v2
worker: python manage.py runworker --settings=myproject.settings -v2

the error from heroku logs --tail

2022-01-07T23:33:49.877754+00:00 app[web.1]: raise InvalidChannelLayerError(
2022-01-07T23:33:49.877754+00:00 app[web.1]: channels.exceptions.InvalidChannelLayerError: ROUT
ING key found for default - this is no longer needed in Channels 2.
2022-01-07T23:33:49.877914+00:00 app[web.1]: 2022-01-07 23:33:49,877 INFO     failing WebSocket
 opening handshake ('Internal server error')
2022-01-07T23:33:49.878083+00:00 app[web.1]: 2022-01-07 23:33:49,878 WARNING  dropping connecti
on to peer tcp4:10.1.83.62:25575 with abort=False: Internal server error
2022-01-07T23:33:49.878720+00:00 app[web.1]: 2022-01-07 23:33:49,878 DEBUG    WebSocket closed
for ['10.1.83.62', 25575]

why it works perfectly in my localhost because I am using only this

CHANNEL_LAYERS = {
    "default": {
        "BACKEND": 'channels.layers.InMemoryChannelLayer'
    }
}
1
  • Hello there, did you find a solution to your problem? I am having a similar issue. Commented Jul 7, 2023 at 10:16

1 Answer 1

0

It's disabled on Heroku.

As it's mentioned in docs, you shouldn't use it in production:

In-memory channel layers operate with each process as a separate layer. This means that no cross-process messaging is possible. As the core value of channel layers is to provide distributed messaging, in-memory usage will result in sub-optimal performance, and ultimately data-loss in a multi-instance environment.

So you have to come up with a Redis solution.

Sign up to request clarification or add additional context in comments.

2 Comments

yes and that's why I am using channels_redis as it is mentionned in docs 'channels_redis is the only official Django-maintained channel layer supported for production use.'
I said in localhost I am using In-memory but if u see as I mentioned before my settings.py configuration I use redis .....and I don't know why my websocket close when I want to send a message ....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.