Skip to content

Commit

Permalink
Make agent quit when systray quits if started by systray
Browse files Browse the repository at this point in the history
Co-authored-by: Vegar Sechmann Molvig <[email protected]>
Co-authored-by: Kim Tore Jensen <[email protected]>
  • Loading branch information
3 people committed May 31, 2024
1 parent fac9639 commit 2ec280d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion cmd/naisdevice-systray/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ func main() {
}

func run(ctx context.Context, notifier notify.Notifier) error {
ctx, cancel := context.WithCancel(ctx)
defer cancel()

otelCancel, err := otel.SetupOTelSDK(ctx, "naisdevice-systray", log)
if err != nil {
log.WithError(err).Warnf("setup OTel SDK")
Expand Down Expand Up @@ -104,7 +107,13 @@ func run(ctx context.Context, notifier notify.Notifier) error {
span.RecordError(err)
return fmt.Errorf("spawning naisdevice-agent: %w", err)
}
defer command.Wait()
defer func() {
cancel()
err := command.Wait()
if err != nil {
log.Errorf("naisdevice-agent exited with error: %v", err)
}
}()
} else {
span.AddEvent("agent.reuse")
err := conn.Close()
Expand Down

0 comments on commit 2ec280d

Please sign in to comment.