engine: resources: Fix a possible panic on closed channel

I don't know how often it happens, but we should catch it.
This commit is contained in:
James Shubin
2019-02-01 03:48:24 -05:00
parent 78936c5ce8
commit fc48fda7e5
2 changed files with 12 additions and 3 deletions

View File

@@ -176,7 +176,10 @@ func (obj *SvcRes) Watch() error {
// loop so that we can see the changed invalid signal
obj.init.Logf("daemon reload")
case event := <-obj.init.Events:
case event, ok := <-obj.init.Events:
if !ok {
return nil
}
if err := obj.init.Read(event); err != nil {
return err
}
@@ -222,7 +225,10 @@ func (obj *SvcRes) Watch() error {
case err := <-subErrors:
return errwrap.Wrapf(err, "unknown %s error", obj)
case event := <-obj.init.Events:
case event, ok := <-obj.init.Events:
if !ok {
return nil
}
if err := obj.init.Read(event); err != nil {
return err
}