jonathanslenders / asyncio-redis

Redis client for Python asyncio (PEP 3156)
http://asyncio-redis.readthedocs.org/
Other
552 stars 74 forks source link

HiRedisProtocol's subscription service is broken #93

Open ghost opened 8 years ago

ghost commented 8 years ago

Using asyncio-redis==0.14.2

Code:

import asyncio
from asyncio_redis import Pool
from asyncio_redis.protocol import HiRedisProtocol, RedisProtocol

@asyncio.coroutine
def read_messages():
    klass = HiRedisProtocol
    # klass = RedisProtocol
    redis_connection = yield from Pool().create(host='redis-01.myserver.com', port=26380, protocol_class=klass)
    redis_subscriber = yield from redis_connection.start_subscribe()
    yield from redis_subscriber.subscribe([':myqueue.something.notification'])
    print("Listening to messages...")
    while True:
        message = yield from redis_subscriber.next_published()
        print("Message recieved: {}".format(message))
    redis_connection.close()

event_loop = asyncio.new_event_loop()
asyncio.set_event_loop(event_loop)
event_loop.run_until_complete(read_messages())

fails with (on startup, and each time a message arrives):

Exception in callback _SelectorSocketTransport._read_ready()
handle: <Handle _SelectorSocketTransport._read_ready()>
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/events.py", line 125, in _run
    self._callback(*self._args)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/selector_events.py", line 667, in _read_ready
    self._protocol.data_received(data)
  File "/Users/agautam/work/git/cash-mgmt-server/venv/lib/python3.5/site-packages/asyncio_redis/protocol.py", line 2446, in data_received
    self._process_hiredis_item(item, self._push_answer)
  File "/Users/agautam/work/git/cash-mgmt-server/venv/lib/python3.5/site-packages/asyncio_redis/protocol.py", line 2459, in _process_hiredis_item
    cb(reply)
  File "/Users/agautam/work/git/cash-mgmt-server/venv/lib/python3.5/site-packages/asyncio_redis/protocol.py", line 1060, in _push_answer
    f = self._queue.popleft()
IndexError: pop from an empty deque

Workaround: Go back to using RedisProtocol.

klass = RedisProtocol

Let me know if you need more info.

Thanks

jonathanslenders commented 8 years ago

This is definitely a bug. Thanks a lot for reporting this! I will probably need some time for this. Not sure what's going on...

ghost commented 8 years ago

Ok. Looking forward.

Thanks

Ajay Gautam Office: 646.454.4648

From: Jonathan Slenders Reply-To: jonathanslenders/asyncio-redis Date: Thursday, March 17, 2016 at 4:24 PM To: jonathanslenders/asyncio-redis Cc: Ajay Gautam Subject: Re: [asyncio-redis] HiRedisProtocol's subscription service is broken (#93)

This is definitely a bug. Thanks a lot for reporting this! I will probably need some time for this. Not sure what's going on...

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHubhttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_jonathanslenders_asyncio-2Dredis_issues_93-23issuecomment-2D198067452&d=CwMCaQ&c=Y88mj8G9kqbn8Ggg2-NXMw&r=xnO0tfku-bhkJ1CNBZbzs1SUTQPF_LPVtf_QQsYeKQ4&m=LJkQhQBRfJOJf7CeloYmsg3T_43SEeV7E4eKcMgSwlw&s=r9jJ9I2W6FzD_VF6PbYAEc7RgAbhKryv9XYprgyTPME&e=

dutradda commented 7 years ago

Any progress here? I want to use pub/sub with asyncio, but I need hiredis support for my client. I still use redis-py until this bug is fixed.

asvetlov commented 7 years ago

@dutradda switch to aioredis :)

dutradda commented 7 years ago

@asvetlov thank you, I will

vgoklani commented 7 years ago

bump