Skip to content

Commit

Permalink
globalcancel
Browse files Browse the repository at this point in the history
  • Loading branch information
abe-winter committed Jan 12, 2025
1 parent 25840a6 commit cdf3fc8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/viam-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type agentOpts struct {
//nolint:gocognit
func commonMain() {
ctx, cancel := setupExitSignalHandling()
agent.GlobalCancel = cancel

defer func() {
cancel()
Expand Down
1 change: 1 addition & 0 deletions subsystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ func (s *AgentSubsystem) Update(ctx context.Context, cfg *pb.DeviceSubsystemConf

func (s *AgentSubsystem) tryInner(ctx context.Context, cfg *pb.DeviceSubsystemConfig, newVersion bool) (bool, error) {
inner, ok := s.inner.(updatable)
s.logger.Infof("in %s tryInner, updatable is %t", s.name, ok)
if ok {
return inner.Update(ctx, cfg, newVersion)
}
Expand Down
5 changes: 4 additions & 1 deletion subsystems/viamagent/viamagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ func (a *agentSubsystem) Update(ctx context.Context, cfg *pb.DeviceSubsystemConf
// if _, err := exec.Command("powershell", "-command", "Restart-Service viam-agent").Output(); err != nil {
// return false, errw.Wrap(err, "restarting windows service")
// }
agent.GlobalManager.CloseAll()
if agent.GlobalCancel == nil {
return false, errors.New("can't call globalCancel because it's nil")
}
agent.GlobalCancel()
return true, nil
}

Expand Down
2 changes: 2 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ var (

// GlobalManager allows subsystems and other contexts to trigger CloseAll.
GlobalManager *Manager
// This lets other things stop the main thread.
GlobalCancel func()
)

// GetVersion returns the version embedded at build time.
Expand Down

0 comments on commit cdf3fc8

Please sign in to comment.