Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

create_sentinel cannot connect to any sentinel #691

Closed
popadi opened this issue Jan 16, 2020 · 11 comments
Closed

create_sentinel cannot connect to any sentinel #691

popadi opened this issue Jan 16, 2020 · 11 comments
Labels
resolved-via-latest This indicates this issue is either resolved or invalid as of the latest version.

Comments

@popadi
Copy link

popadi commented Jan 16, 2020

Hello!

I have the following piece of code:

import asyncio
import aioredis

async def test():
    sentinel = await aioredis.create_sentinel([('ti-redis-sentinel', 26379)])
    redis = sentinel.master_for('redis')

asyncio.run(test())

It perfectly works in a jupyter notebook, but it doesn't work inside a container.

[apop@8968ad4f43a2 worker]$ python test.py
Traceback (most recent call last):
  File "test.py", line 8, in <module>
    asyncio.run(test())
  File "/jump/software/rhel7/Python-3.7.3/lib/python3.7/asyncio/runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "/jump/software/rhel7/Python-3.7.3/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
    return future.result()
  File "test.py", line 5, in test
    sentinel = await aioredis.create_sentinel([('ti-redis-sentinel', 26379)])
  File "/data/home/venv/mon-worker/lib/python3.7/site-packages/aioredis/sentinel/commands.py", line 27, in create_sentinel
    loop=loop)
  File "/data/home/venv/mon-worker/lib/python3.7/site-packages/aioredis/sentinel/pool.py", line 46, in create_sentinel_pool
    await pool.discover()
  File "/data/home/venv/mon-worker/lib/python3.7/site-packages/aioredis/sentinel/pool.py", line 219, in discover
    raise Exception("Could not connect to any sentinel")
Exception: Could not connect to any sentinel

If I do redis-cli -h ti-redis-sentinel -p 26379 and then run sentinel get-master-addr-by-name redis I do receive some entries.
What could be the cause of the error?

@mathias-sa
Copy link

I'm having the same issue here. Connecting with redis-cli works fine but not with aioredis.

@mohammadhzp
Copy link

Did you configure sentinel to require a password for authentication?

@popadi
Copy link
Author

popadi commented May 11, 2020

Did you configure sentinel to require a password for authentication?

No. At the moment the database can be accessed without authentication. After 5 months, the problem is still there.

@mathias-sa
Copy link

I could fix this by disabling the password on the Sentinel itself. It seems that there's some issue when both the sentinel and Redis have a password.

@popadi
Copy link
Author

popadi commented May 11, 2020

I just tried to play randomly with create_sentinel and I noticed something extremely strange. If I have the following:

with await aioredis.create_sentinel([('ti-redis-sentinel', 26379)]) as sentinel:
    redis = sentinel.master_for('redis')
    self.redis = redis

x = await self.redis.get('test-key')
print(x)

It doesn't work, I still get the Exception: Could not connect to any sentinel stuff. If I replace the with - as block with a simple assignment and then try the get, nope, still not working.

However, if I replace the with - as with a simple assignment and I have multiple elements in the array that's passed to create_sentinel, in about half the cases that print actually prints something!

test = [('ti-redis-sentinel', 26379) for i in range(5)]
sentinel = await aioredis.create_sentinel(test)
redis = sentinel.master_for('redis')
self.redis = redis

x = await self.redis.get('test-key')
print(x)

(note that self exists in my code because this is part of a method in a class)

If I try with numbers higher than 5, the chances to work are also higher. What is actually happening? This looks very strange!

@gdub
Copy link

gdub commented Sep 28, 2020

I've seen the same error on network connections with higher latency to the Redis server(s). For me, errors went away if I increased the timeout value passed to create_sentinel.

The default timeout value is 0.2 seconds, which may be too short. There are debug statements in the logic when a connection timeout occurs (https://github.com/aio-libs/aioredis/blob/master/aioredis/sentinel/pool.py#L243), but unless you are logging at debug level, you may not see them.

@sadilet
Copy link

sadilet commented Nov 26, 2020

@popadi Here you can find solution of this issue. Currently, this library does not support sentinel authentication. It's going to be deployed. Password argument of create_sentinel function is actually Redis' password, not Sentinel.

@popadi
Copy link
Author

popadi commented Nov 26, 2020

@popadi Here you can find solution of this issue. Currently, this library does not support sentinel authentication. It's going to be deployed. Password argument of create_sentinel function is actually Redis' password, not Sentinel.

Hello! As I said before, I'm not using any passwords and I still have this issue.

@seandstewart
Copy link
Collaborator

@popadi - as of #891, aioredis is a running port of redis-py, so the sentinel behavior should be exactly the same. Can you test your problem on the latest master and see if it persists?

@seandstewart seandstewart added the resolved-via-latest This indicates this issue is either resolved or invalid as of the latest version. label Mar 18, 2021
@popadi
Copy link
Author

popadi commented Apr 9, 2021

@popadi - as of #891, aioredis is a running port of redis-py, so the sentinel behavior should be exactly the same. Can you test your problem on the latest master and see if it persists?

Hey and sorry for the delay. Indeed, I installed aioredis from the master branch and for the first time I saw in my logs the success message. As someone posted in the original PR, there are a lot of breaking changes, but in my case I only had to change the sentinel initialization.

Guess I'll wait for a release 😄 Thank you!
Do you have any idea about the underlying issue that caused this?

@Andrew-Chen-Wang
Copy link
Collaborator

I think this was more about v1.3.1, so I'll close this. Also the master branch version from 29 days ago (I believe) is from the redis-py port, so we gtg.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
resolved-via-latest This indicates this issue is either resolved or invalid as of the latest version.
Projects
None yet
Development

No branches or pull requests

7 participants