Skip to content

Commit

Permalink
fix: Don't leave a bad future in place when client creation fails (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpcollins-google committed Aug 15, 2022
1 parent 62b9946 commit 86cf1c0
Showing 1 changed file with 7 additions and 1 deletion.
Expand Up @@ -87,7 +87,13 @@ def __init__(
async def get_or_create(self, key: _Key) -> _Client:
if key not in self._live_clients:
self._live_clients[key] = asyncio.ensure_future(self._factory(key))
return await self._live_clients[key]
future = self._live_clients[key]
try:
return await future
except BaseException as e:
if key in self._live_clients and self._live_clients[key] is future:
del self._live_clients[key]
raise e

async def try_erase(self, key: _Key, client: _Client):
if key not in self._live_clients:
Expand Down

0 comments on commit 86cf1c0

Please sign in to comment.