Skip to content

Commit

Permalink
Monitors the addr file creation
Browse files Browse the repository at this point in the history
By means of the Filesystem events API.
That ensures we don't launch the agent more than once,
until startup timeouts.
  • Loading branch information
CarlosNihelton committed Oct 23, 2023
1 parent 286bdcd commit ddf7c77
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions gui/packages/ubuntupro/lib/pages/startup/agent_monitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ddf7c77

Please sign in to comment.