From ddf7c775f2bbefe90d509b6e0ed0107917b0b553 Mon Sep 17 00:00:00 2001 From: Carlos Date: Mon, 23 Oct 2023 12:02:45 -0300 Subject: [PATCH] Monitors the addr file creation By means of the Filesystem events API. That ensures we don't launch the agent more than once, until startup timeouts. --- gui/packages/ubuntupro/lib/pages/startup/agent_monitor.dart | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gui/packages/ubuntupro/lib/pages/startup/agent_monitor.dart b/gui/packages/ubuntupro/lib/pages/startup/agent_monitor.dart index d092c8cc2..962557e6f 100644 --- a/gui/packages/ubuntupro/lib/pages/startup/agent_monitor.dart +++ b/gui/packages/ubuntupro/lib/pages/startup/agent_monitor.dart @@ -127,10 +127,16 @@ class AgentStartupMonitor { // Terminal state, cannot recover nor retry. return AgentState.unknownEnv; case AgentAddrFileError.nonexistent: + // The directory must exist so we can watch for changes. This won't fail if the directory already exists. + final agentDir = await File(_addrFilePath!).parent.create(); + final watch = agentDir + .watch(events: FileSystemEvent.create) + .firstWhere((event) => event.path.contains(_addrFilePath!)); if (!await agentLauncher()) { // Terminal state, cannot recover nor retry. return AgentState.cannotStart; } + await watch; return AgentState.starting; // maybe a race condition allowed us to read the file before write completed? Retry. // ignore: switch_case_completes_normally