Skip to content

Commit

Permalink
runner/streamer: Fix nested process restart (#361)
Browse files Browse the repository at this point in the history
We call the stop/restart function from coroutines that
will be stopped as well by such functions. As such
we should not await them otherwise there will be a
recursive cancellation happening.

The right way is to create_task and let them execute
in backgrund.
  • Loading branch information
victorges authored Dec 12, 2024
1 parent 23a10c7 commit bb402bf
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions runner/app/live/streamer/streamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ async def monitor_loop(self, done: Event):

if self.input_timeout > 0 and time_since_last_input > self.input_timeout:
logging.info(f"Input stream stopped for {time_since_last_input} seconds. Shutting down...")
await asyncio.create_task(self.stop())
asyncio.create_task(self.stop())
return

gone_stale = (
Expand All @@ -249,7 +249,7 @@ async def monitor_loop(self, done: Event):
logging.warning(
"No output received while inputs are being sent. Restarting process."
)
await self._restart()
asyncio.create_task(self._restart())
return

async def run_ingress_loop(self, done: Event):
Expand Down Expand Up @@ -294,7 +294,7 @@ async def run_ingress_loop(self, done: Event):
await self.stop()
except Exception:
logging.error("Error running ingress loop", exc_info=True)
await self._restart()
asyncio.create_task(self._restart())

async def run_egress_loop(self, done: Event):
async def gen_output_frames() -> AsyncGenerator[Image.Image, None]:
Expand Down Expand Up @@ -330,7 +330,7 @@ async def gen_output_frames() -> AsyncGenerator[Image.Image, None]:
await self.stop()
except Exception:
logging.error("Error running egress loop", exc_info=True)
await self._restart()
asyncio.create_task(self._restart())

async def run_control_loop(self):
"""Consumes control messages from the protocol and updates parameters"""
Expand Down

0 comments on commit bb402bf

Please sign in to comment.