title: Django channels with redis setup on heroku leaking memory
body: <p>I followed the somewhat outdated guide here:
  <a href="https://blog.heroku.com/in_deep_with_django_channels_the_future_of_real_time_apps_in_django" rel="nofollow noreferrer">https://blog.heroku.com/in_deep_with_django_channels_the_future_of_real_time_apps_in_django</a></p>
  
  <p>And successfully setup django app with channels:</p>
  
  <pre><code>&gt; cat requirements.txt 
  ..
  Django==1.10.6
  asgi-redis==1.4.3
  asgiref==1.1.2
  channels==1.1.8
  django-redis-cache==1.7.1
  daphne==1.4.2
  ..
  
  &gt; cat Procfile 
  web: daphne Landia.asgi:channel_layer --port $PORT --bind 0.0.0.0
  worker: python manage.py runworker
  
  CHANNEL_LAYERS = {
      "default": {
          "BACKEND": "asgi_redis.RedisChannelLayer",
          "CONFIG": {
              "hosts": [os.environ.get('REDIS_URL', 'redis://localhost:6379')],
          },
          "ROUTING": "Landia.routing.channel_routing",
      },
  }
  </code></pre>
  
  <p>The problem being is that the redis memory consumption starts at 2M, and gradually, very slowly, over 48 hours or so grows to 50MB when the provisioned space is exhausted and my server essentially starts throwing 5XX.</p>
  
  <p>It can be fixed by flushing redis.</p>
  
  <p>I assuming the channels/redis are not discarding the replies it sends out.</p>
  
  <p><a href="https://i.stack.imgur.com/bxJSH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bxJSH.png" alt="Screenshot with redis mem usage"></a></p>
  
  <p>Any ideas how to fix, or at least debug this problem?</p>
  
  <p>I also use redis for session storage, which I think is the source of leak:</p>
  
  <pre><code>&gt; heroku redis:cli
  &gt; info
  ...
  # Keyspace
  db0:keys=119,expires=119,avg_ttl=49389233
  db1:keys=7749,expires=7749,avg_ttl=1192828136
  &gt; select 1
  &gt; keys *
  ...
  7757) :1:django.contrib.sessions.cachechnb5cafa749ec3b1b8b6fc20903750f
  7758) :1:django.contrib.sessions.cachechn975ee5d806f3b27d6492e3fad8218
  7759) :1:django.contrib.sessions.cachechn659906572f30ed388e655b75fbf87
  </code></pre>
  
  <p>Here's the django channels session setup:</p>
  
  <pre><code>CHANNEL_SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
  
  CACHES = {
      'default': {
          'BACKEND': 'redis_cache.RedisCache',
          'LOCATION': os.environ.get('REDIS_URL', 'redis://localhost:6379')
      },
  }
  </code></pre>
  
  <p>And usage in consumers.py</p>
  
  <pre><code>@allowed_hosts_only
  @channel_session_user_from_http
  def ws_connect(message):
      ...
  
  
  @channel_session_user
  def ws_receive(message):
     ...
  
  
  @channel_session_user
  def ws_disconnect(message):
      ...
  </code></pre>
  
  <p>Is there a way to clean the session info being stored in redis on disconnect, or at least set up sensible TTL for the redis keys?</p>