Fix race condition when updating process being waited on (#1694)
This commit is contained in:
parent
00b76e0a64
commit
0ce132eb8f
@ -197,11 +197,20 @@ func (s *service) Error() error {
|
|||||||
// Wait waits for the service to finish running
|
// Wait waits for the service to finish running
|
||||||
func (s *service) Wait() {
|
func (s *service) Wait() {
|
||||||
// wait for process to exit
|
// 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()
|
s.Lock()
|
||||||
defer s.Unlock()
|
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
|
// save the error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if logger.V(logger.ErrorLevel, logger.DefaultLogger) {
|
if logger.V(logger.ErrorLevel, logger.DefaultLogger) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user