Skip to content

Commit

Permalink
Avoid leaking proservices Manager on teardown
Browse files Browse the repository at this point in the history
When we call agent.Quit, we don't wait for the proServices to
perform their cleanup. This means that the process can exit while the
Landscape, registry watcher or database are in the middle of an
operation.

This PR fixes this, somewhat: It guarantees to exit the process after
proservices.Stop returns. We trust that the implementation of the
teardown of these proservices is implemented properly.

This problem also affected tests, as the proServices could be writing to
disk while t.Cleanup tries to delete the temp directory, causing a race
and then a test error.
  • Loading branch information
EduardGomezEscandell committed Mar 26, 2024
1 parent e0d45f9 commit 2483fdb
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions windows-agent/cmd/ubuntu-pro-agent/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ type App struct {
viper *viper.Viper
config daemonConfig

daemon *daemon.Daemon
daemon *daemon.Daemon
proServices *proservices.Manager

ready chan struct{}
}
Expand Down Expand Up @@ -125,7 +126,7 @@ func (a *App) serve(args ...option) error {

log.Debugf(ctx, "Agent private directory: %s", privateDir)

proservice, err := proservices.New(ctx,
proservices, err := proservices.New(ctx,
publicDir,
privateDir,
proservices.WithRegistry(opt.registry),
Expand All @@ -134,9 +135,9 @@ func (a *App) serve(args ...option) error {
close(a.ready)
return err
}
defer proservice.Stop(ctx)
a.proServices = &proservices

a.daemon = daemon.New(ctx, proservice.RegisterGRPCServices, publicDir)
a.daemon = daemon.New(ctx, proservices.RegisterGRPCServices, publicDir)

close(a.ready)

Expand Down Expand Up @@ -184,6 +185,7 @@ func (a *App) Quit() {
return
}
a.daemon.Quit(context.Background(), false)
a.proServices.Stop(context.Background())
}

// WaitReady signals when the daemon is ready
Expand Down

0 comments on commit 2483fdb

Please sign in to comment.