Skip to content

Commit

Permalink
Merge pull request #635 from minrk/wait-for-start-error
Browse files Browse the repository at this point in the history
catch errors in reflector.start
  • Loading branch information
consideRatio committed Aug 29, 2022
2 parents f3d44e6 + 9256781 commit 66086a9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
11 changes: 9 additions & 2 deletions kubespawner/reflector.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,16 @@ async def start(self):
and not afterwards!
"""
if self.watch_task and not self.watch_task.done():
raise RuntimeError('Task watching for resources is already running')
raise RuntimeError(f"Task watching for {self.kind} is already running")
try:
await self._list_and_update()
except Exception as e:
self.log.exception(f"Initial list of {self.kind} failed")
if not self.first_load_future.done():
# anyone awaiting our first load event should fail
self.first_load_future.set_exception(e)
raise

await self._list_and_update()
self.watch_task = asyncio.create_task(self._watch_and_update())

async def stop(self):
Expand Down
11 changes: 10 additions & 1 deletion kubespawner/spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2393,7 +2393,16 @@ def on_reflector_failure():
on_failure=on_reflector_failure,
**kwargs,
)
asyncio.ensure_future(self.__class__.reflectors[key].start())
f = asyncio.ensure_future(self.__class__.reflectors[key].start())

async def catch_reflector_start():
try:
await f
except Exception as e:
self.log.exception(f"Reflector for {kind} failed to start.")
sys.exit(1)

asyncio.create_task(catch_reflector_start())

if replace and previous_reflector:
# we replaced the reflector, stop the old one
Expand Down

0 comments on commit 66086a9

Please sign in to comment.