channels_redis icon indicating copy to clipboard operation
channels_redis copied to clipboard

Exception inside application: Reader at end of file

Open Hapyr opened this issue 5 years ago • 7 comments

I have a Error Log in my Daphne Log:

2019-04-26 16:54:57,916 ERROR Exception inside application: Reader at end of file File "/usr/lib/python3.5/asyncio/tasks.py", line 241, in _step result = coro.throw(exc) File "/home/gebler/vesl/lib/python3.5/site-packages/channels/sessions.py", line 183, in call return await self.inner(receive, self.send) File "/home/gebler/vesl/lib/python3.5/site-packages/channels/middleware.py", line 41, in coroutine_call await inner_instance(receive, send) File "/home/gebler/vesl/lib/python3.5/site-packages/channels/consumer.py", line 59, in call [receive, self.channel_receive], self.dispatch File "/home/gebler/vesl/lib/python3.5/site-packages/channels/utils.py", line 59, in await_many_dispatch await task File "/usr/lib/python3.5/asyncio/futures.py", line 382, in iter return self.result() # May raise too. File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result raise self._exception File "/home/gebler/vesl/lib/python3.5/site-packages/channels/utils.py", line 51, in await_many_dispatch result = task.result() File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result raise self._exception File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step result = coro.send(None) File "/home/gebler/vesl/lib/python3.5/site-packages/channels_redis/core.py", line 429, in receive real_channel File "/home/gebler/vesl/lib/python3.5/site-packages/channels_redis/core.py", line 484, in receive_single index, channel_key, timeout=self.brpop_timeout File "/home/gebler/vesl/lib/python3.5/site-packages/channels_redis/core.py", line 327, in _brpop_with_clean await connection.eval(cleanup_script, keys=[], args=[channel, backup_queue]) File "/home/gebler/vesl/lib/python3.5/site-packages/aioredis/commands/scripting.py", line 12, in eval return self.execute(b'EVAL', script, len(keys), *(keys + args)) File "/home/gebler/vesl/lib/python3.5/site-packages/aioredis/commands/init.py", line 51, in execute return self._pool_or_conn.execute(command, *args, **kwargs) File "/home/gebler/vesl/lib/python3.5/site-packages/aioredis/connection.py", line 319, in execute raise ConnectionClosedError(msg) Reader at end of file

Im using a Debian 9 Server with Apache2 to host 2 Websites. So i config it as reverse Proxy to a Daphne Server where my Application running on. backend storage is managed with Redis-Server and channels_redis:

ASGI_APPLICATION = "vel_2_0.routing.application" CHANNEL_LAYERS = { 'default': { 'BACKEND': 'channels_redis.core.RedisChannelLayer', 'CONFIG': { "hosts": [('127.0.0.1', 6379)], }, }, }

My small Application is a Multiplayer Game i would like to play it with over 60 People at the same time. With 1 to 10 People there is no Problem and everything works fine. But at some Random number of Users the Daphne Server throw this Error and didnt answer anymore. But the WebSocket didnt close the Connection. The Error is only triggerd by connect and/or disconnect. So for Example if there are 10 user online and playing and one of them press f5, in some random cases this Error is thrown. So i think there is something wrong with the comunication between Redis backend an Daphne.

Hapyr avatar Apr 27 '19 15:04 Hapyr

This error is caused by Python 3.5. It seems to be the same bug as in Issue https://github.com/django/channels_redis/issues/145

Maybe you should pay more attention to it somewhere in the Docs!

Hapyr avatar Apr 27 '19 17:04 Hapyr

Same error with Python 3.7.3:

2019-05-02 07:09:47,757 ERROR    Exception inside application: Reader at end of file
  File "/usr/local/lib/python3.7/site-packages/channels/sessions.py", line 183, in __call__
    return await self.inner(receive, self.send)
  File "/usr/local/lib/python3.7/site-packages/channels/middleware.py", line 41, in coroutine_call
    await inner_instance(receive, send)
  File "/usr/local/lib/python3.7/site-packages/channels/consumer.py", line 59, in __call__
    [receive, self.channel_receive], self.dispatch
  File "/usr/local/lib/python3.7/site-packages/channels/utils.py", line 52, in await_many_dispatch
    await dispatch(result)
  File "/usr/local/lib/python3.7/site-packages/asgiref/sync.py", line 150, in __call__
    return await asyncio.wait_for(future, timeout=None)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 388, in wait_for
    return await fut
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.7/site-packages/channels/db.py", line 14, in thread_handler
    return super().thread_handler(loop, *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/asgiref/sync.py", line 169, in thread_handler
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/channels/consumer.py", line 105, in dispatch
    handler(message)
  File "/usr/local/lib/python3.7/site-packages/channels/generic/websocket.py", line 106, in websocket_disconnect
    self.disconnect(message["code"])
  File "/project/platform/project/websockets/consumers.py", line 122, in disconnect
    async_to_sync(self.channel_layer.group_discard)(self.get_client_group(), self.channel_name)
  File "/usr/local/lib/python3.7/site-packages/asgiref/sync.py", line 79, in __call__
    return call_result.result()
  File "/usr/local/lib/python3.7/concurrent/futures/_base.py", line 432, in result
    return self.__get_result()
  File "/usr/local/lib/python3.7/concurrent/futures/_base.py", line 384, in __get_result
    raise self._exception
  File "/usr/local/lib/python3.7/site-packages/asgiref/sync.py", line 95, in main_wrap
    result = await self.awaitable(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/channels_redis/core.py", line 599, in group_discard
    await connection.zrem(key, channel)
  File "/usr/local/lib/python3.7/site-packages/aioredis/commands/sorted_set.py", line 224, in zrem
    return self.execute(b'ZREM', key, member, *members)
  File "/usr/local/lib/python3.7/site-packages/aioredis/commands/__init__.py", line 51, in execute
    return self._pool_or_conn.execute(command, *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/aioredis/connection.py", line 319, in execute
    raise ConnectionClosedError(msg)
  Reader at end of file

ghost avatar May 02 '19 08:05 ghost

same thing here, anyone find solution or root cause for this? any idea?

kmkmjhyiiiu avatar Jun 08 '20 21:06 kmkmjhyiiiu

I didn't found any solution and I never had this issue again with python 3.8.

Hapyr avatar Jun 08 '20 21:06 Hapyr

ok thanks let me try.

kmkmjhyiiiu avatar Jun 08 '20 21:06 kmkmjhyiiiu

I got this error also.

I debugged it and I found the reason for the error is about SSL config.

CHANNEL_LAYERS = {
    'default': {
        'BACKEND': 'channels_redis.core.RedisChannelLayer',
        'CONFIG': {
            'hosts': [("redis://:[email protected]:1111/0")], # 1111 is port number
        },
    },
}

While my Redis instance connection works on TLS(SSL) the connection was failing. And I found how to enable it on aioredis.util.parse_url function.  So I need to change redis with rediss to enable it.

Like: hosts': [("rediss://:[email protected]:1111/0")]

ishakoktn avatar Mar 08 '22 11:03 ishakoktn

I have this same issue with Python 3.8.10. It's probably related to a pip package version not to a python version

Kaju-Bubanja avatar May 30 '22 13:05 Kaju-Bubanja

This looks like a connection issue rather than anything to do with channels_redis.

carltongibson avatar Oct 07 '22 09:10 carltongibson