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

Failing to discover sentinel instances results "Task was destroyed but it is pending!" #742

Closed
mohammadhzp opened this issue May 10, 2020 · 1 comment
Labels
resolved-via-latest This indicates this issue is either resolved or invalid as of the latest version.

Comments

@mohammadhzp
Copy link

mohammadhzp commented May 10, 2020

Currently calling aioredis.create_sentinel() makes a call to create_sentinel_pool(),

now create_sentinel_pool() create a sentinel pool using SentinelPool and then call its discover() method.
What we need to consider is that SentinelPool class starts a coroutine in its constructor called echo_events.

At this point, when discover() didn't get to connect to any sentinel. it raises an Exception but create_sentinel_pool does not handle that error. you see, SentinelPool started a coroutine on initializing. so calling close() on SentinelPool is mandatory. especially when create_sentinel_pool() is the only one that can access "pool object" in case of an error.
That is why "Task was destroyed but it is pending!" happens.

This is how the last two lines of create_sentinel_pool() look like:

await pool.discover()
return pool

I think it should be:

try:
    await pool.discover()
except BaseException:
    pool.close()
    await pool.wait_closed()
    raise
@seandstewart
Copy link
Collaborator

This issue should be resolved as of #891 - please feel free to pull in the latest master and test to ensure this is the case.

@seandstewart seandstewart added the resolved-via-latest This indicates this issue is either resolved or invalid as of the latest version. label Mar 19, 2021
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

2 participants