Skip to content

Commit

Permalink
fix: Fixed an issue where when the DaemonController fails to start th…
Browse files Browse the repository at this point in the history
…e daemon process, the fork of the Kraken process continues, resulting in two copies of the process trying to run to completion, e.g. executing tasks from this point on. (#218)
  • Loading branch information
NiklasRosenstein authored Mar 14, 2024
1 parent 5c054dc commit ec166ad
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changelog/_unreleased.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[[entries]]
id = "654174ac-b3d2-476a-b761-e65c8f4dd8a5"
type = "fix"
description = "Fixed an issue where when the DaemonController fails to start the daemon process, the fork of the Kraken process continues, resulting in two copies of the process trying to run to completion, e.g. executing tasks from this point on."
author = "[email protected]"
7 changes: 5 additions & 2 deletions kraken-build/src/kraken/std/util/daemon_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ def spawn_fork(func: Callable[[], Any], detach: bool = True) -> int:
return pid
if detach:
os.setsid()
func()
os._exit(os.EX_OK)
try:
func()
finally:
os._exit(os.EX_OK)


def replace_stdio(stdin: int | None = None, stdout: int | None = None, stderr: int | None = None) -> None:
Expand Down Expand Up @@ -240,6 +242,7 @@ def start_daemon() -> None:
state = self.State(command, str(cwd), env, proc.pid, time.time())
self.save_state(state)

logger.debug("Spawning fork to start daemon %s", self.name)
pid = spawn_fork(start_daemon)
if status := wait_for_child_process(pid, 10.0):
raise Exception("An unexpected error ocurred when starting daemon %r (exit code %s).", self.name, status)
Expand Down

0 comments on commit ec166ad

Please sign in to comment.