Skip to content

Commit

Permalink
Have stopService check service state before attempting to control it.
Browse files Browse the repository at this point in the history
Control returns an error if the service is already stopped, so this avoids an error in situations where the stop is effectively already accomplished.

PiperOrigin-RevId: 437807711
  • Loading branch information
ItsMattL authored and copybara-github committed Mar 28, 2022
1 parent 666bf0a commit 91d189d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion go/helpers/helpers_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,15 @@ func StartService(name string) error {
}

func stopService(s *mgr.Service) error {
stat, err := s.Control(svc.Stop)
// although s.Control returns stat, if the service is already stopped it returns an error
stat, err := s.Query()
if err != nil {
return err
}
if stat.State == svc.Stopped {
return nil
}
stat, err = s.Control(svc.Stop)
if err != nil {
return err
}
Expand Down

0 comments on commit 91d189d

Please sign in to comment.