Skip to content

Commit 26de2a1

Browse files
Merge pull request #372 from wking/precise-context-error
Bug 1838497: pkg/cvo/sync_worker: Do not treat "All errors were context errors..." as success
2 parents 44b4f78 + 1033fa4 commit 26de2a1

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

pkg/cvo/sync_worker.go

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,8 @@ func (w *SyncWorker) apply(ctx context.Context, payloadUpdate *payload.Update, w
625625
if precreateObjects {
626626
payload.RunGraph(ctx, graph, 8, func(ctx context.Context, tasks []*payload.Task) error {
627627
for _, task := range tasks {
628-
if contextIsCancelled(ctx) {
629-
return cr.CancelError()
628+
if err := ctx.Err(); err != nil {
629+
return cr.ContextError(err)
630630
}
631631
if task.Manifest.GVK != configv1.SchemeGroupVersion.WithKind("ClusterOperator") {
632632
continue
@@ -644,8 +644,8 @@ func (w *SyncWorker) apply(ctx context.Context, payloadUpdate *payload.Update, w
644644
// update each object
645645
errs := payload.RunGraph(ctx, graph, maxWorkers, func(ctx context.Context, tasks []*payload.Task) error {
646646
for _, task := range tasks {
647-
if contextIsCancelled(ctx) {
648-
return cr.CancelError()
647+
if err := ctx.Err(); err != nil {
648+
return cr.ContextError(err)
649649
}
650650
cr.Update()
651651

@@ -667,8 +667,10 @@ func (w *SyncWorker) apply(ctx context.Context, payloadUpdate *payload.Update, w
667667
return nil
668668
})
669669
if len(errs) > 0 {
670-
err := cr.Errors(errs)
671-
return err
670+
if err := cr.Errors(errs); err != nil {
671+
return err
672+
}
673+
return errs[0]
672674
}
673675

674676
// update the status
@@ -689,11 +691,11 @@ func init() {
689691
)
690692
}
691693

692-
type errCanceled struct {
694+
type errContext struct {
693695
err error
694696
}
695697

696-
func (e errCanceled) Error() string { return e.err.Error() }
698+
func (e errContext) Error() string { return e.err.Error() }
697699

698700
// consistentReporter hides the details of calculating the status based on the progress
699701
// of the graph runner.
@@ -730,7 +732,7 @@ func (r *consistentReporter) Error(err error) {
730732
copied := r.status
731733
copied.Step = "ApplyResources"
732734
copied.Fraction = float32(r.done) / float32(r.total)
733-
if !isCancelledError(err) {
735+
if !isContextError(err) {
734736
copied.Failure = err
735737
}
736738
r.reporter.Report(copied)
@@ -751,10 +753,10 @@ func (r *consistentReporter) Errors(errs []error) error {
751753
return err
752754
}
753755

754-
func (r *consistentReporter) CancelError() error {
756+
func (r *consistentReporter) ContextError(err error) error {
755757
r.lock.Lock()
756758
defer r.lock.Unlock()
757-
return errCanceled{fmt.Errorf("update was cancelled at %d of %d", r.done, r.total)}
759+
return errContext{fmt.Errorf("update %s at %d of %d", err, r.done, r.total)}
758760
}
759761

760762
func (r *consistentReporter) Complete() {
@@ -770,11 +772,11 @@ func (r *consistentReporter) Complete() {
770772
r.reporter.Report(copied)
771773
}
772774

773-
func isCancelledError(err error) bool {
775+
func isContextError(err error) bool {
774776
if err == nil {
775777
return false
776778
}
777-
_, ok := err.(errCanceled)
779+
_, ok := err.(errContext)
778780
return ok
779781
}
780782

@@ -795,11 +797,12 @@ func isImageVerificationError(err error) bool {
795797
// not truly an error (cancellation).
796798
// TODO: take into account install vs upgrade
797799
func summarizeTaskGraphErrors(errs []error) error {
798-
// we ignore cancellation errors since they don't provide good feedback to users and are an internal
799-
// detail of the server
800-
err := errors.FilterOut(errors.NewAggregate(errs), isCancelledError)
800+
// we ignore context errors (canceled or timed out) since they don't
801+
// provide good feedback to users and are an internal detail of the
802+
// server
803+
err := errors.FilterOut(errors.NewAggregate(errs), isContextError)
801804
if err == nil {
802-
klog.V(4).Infof("All errors were cancellation errors: %v", errs)
805+
klog.V(4).Infof("All errors were context errors: %v", errs)
803806
return nil
804807
}
805808
agg, ok := err.(errors.Aggregate)
@@ -966,16 +969,6 @@ func ownerRefModifier(config *configv1.ClusterVersion) resourcebuilder.MetaV1Obj
966969
}
967970
}
968971

969-
// contextIsCancelled returns true if the provided context is cancelled.
970-
func contextIsCancelled(ctx context.Context) bool {
971-
select {
972-
case <-ctx.Done():
973-
return true
974-
default:
975-
return false
976-
}
977-
}
978-
979972
// runThrottledStatusNotifier invokes fn every time ch is updated, but no more often than once
980973
// every interval. If bucket is non-zero then the channel is throttled like a rate limiter bucket.
981974
func runThrottledStatusNotifier(stopCh <-chan struct{}, interval time.Duration, bucket int, ch <-chan SyncWorkerStatus, fn func()) {

0 commit comments

Comments
 (0)