mirror of
https://github.com/niusmallnan/steve.git
synced 2025-05-05 14:37:07 +00:00
proxy_store: improve error handling
This prevents a goroutine leak when item.Object is a `runtime.Object` but not a `metav1.Object`, as in that case `WatchNames`’s `for` loop will quit early and subsequent calls to `returnErr` will remain parked forever. This helps with https://github.com/rancher/rancher/issues/41225 Fuller explanation in https://github.com/rancher/steve/pull/107
This commit is contained in:
parent
3cbeea22d3
commit
7010a5e6c7
@ -311,7 +311,6 @@ func (s *Store) listAndWatch(apiOp *types.APIRequest, client dynamic.ResourceInt
|
||||
rowToObject(obj)
|
||||
result <- watch.Event{Type: watch.Modified, Object: obj}
|
||||
} else {
|
||||
logrus.Debugf("notifier watch error: %v", err)
|
||||
returnErr(errors.Wrapf(err, "notifier watch error: %v", err), result)
|
||||
}
|
||||
}
|
||||
@ -323,7 +322,6 @@ func (s *Store) listAndWatch(apiOp *types.APIRequest, client dynamic.ResourceInt
|
||||
for event := range watcher.ResultChan() {
|
||||
if event.Type == watch.Error {
|
||||
if status, ok := event.Object.(*metav1.Status); ok {
|
||||
logrus.Debugf("event watch error: %s", status.Message)
|
||||
returnErr(fmt.Errorf("event watch error: %s", status.Message), result)
|
||||
} else {
|
||||
logrus.Debugf("event watch error: could not decode event object %T", event.Object)
|
||||
@ -363,12 +361,22 @@ func (s *Store) WatchNames(apiOp *types.APIRequest, schema *types.APISchema, w t
|
||||
go func() {
|
||||
defer close(result)
|
||||
for item := range c {
|
||||
if item.Type == watch.Error {
|
||||
if status, ok := item.Object.(*metav1.Status); ok {
|
||||
logrus.Debugf("WatchNames received error: %s", status.Message)
|
||||
} else {
|
||||
logrus.Debugf("WatchNames received error: %v", item)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
m, err := meta.Accessor(item.Object)
|
||||
if err != nil {
|
||||
return
|
||||
logrus.Debugf("WatchNames cannot process unexpected object: %s", err)
|
||||
continue
|
||||
}
|
||||
if item.Type != watch.Error && names.Has(m.GetName()) {
|
||||
|
||||
if names.Has(m.GetName()) {
|
||||
result <- item
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user