Fix race condition when updating process being waited on (#1694)

This commit is contained in:
Dominic Wong 2020-06-10 09:36:41 +01:00
parent 00b76e0a64
commit 0ce132eb8f

View File

@ -197,11 +197,20 @@ func (s *service) Error() error {
// Wait waits for the service to finish running
func (s *service) Wait() {
// wait for process to exit
err := s.Process.Wait(s.PID)
s.RLock()
thisPID := s.PID
s.RUnlock()
err := s.Process.Wait(thisPID)
s.Lock()
defer s.Unlock()
if s.PID.ID != thisPID.ID {
// trying to update when it's already been switched out, ignore
logger.Warnf("Trying to update a process status but PID doesn't match. Old %s, New %s. Skipping update.", thisPID.ID, s.PID.ID)
return
}
// save the error
if err != nil {
if logger.V(logger.ErrorLevel, logger.DefaultLogger) {