Skip to content

Commit

Permalink
await first_load_future in reflectors
Browse files Browse the repository at this point in the history
  • Loading branch information
minrk committed Aug 14, 2023
1 parent 698d54b commit f210225
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions kubespawner/spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2185,10 +2185,6 @@ async def poll(self):
just Falsy, to determine that the pod is still running.
"""

reflector = await self._start_watching_pods()
if not reflector.first_load_future.done():
await reflector.first_load_future

ref_key = f"{self.namespace}/{self.pod_name}"
pod = self.pod_reflector.pods.get(ref_key, None)
if pod is not None:
Expand Down Expand Up @@ -2358,6 +2354,10 @@ async def _start_reflector(

if previous_reflector and not replace:
# fast path
if not previous_reflector.first_load_future.done():
# make sure it's loaded, so subsequent calls to start_reflector
# don't finish before the first
await previous_reflector.first_load_future
return previous_reflector

if self.enable_user_namespaces:
Expand Down Expand Up @@ -2406,6 +2406,9 @@ async def catch_reflector_start(func):
# we replaced the reflector, stop the old one
asyncio.ensure_future(previous_reflector.stop())

# wait for first load
await current_reflector.first_load_future

# return the current reflector
return current_reflector

Expand Down

0 comments on commit f210225

Please sign in to comment.