Manager startup spins after cancellation before cache readiness

Aperta
#3,629 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
57/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go
Ambito
backend

Direzione di ricerca

Start with runnableGroup.Start and the cache startup call in (*controllerManager).Start, where the issue says cancellation leaves startup waiting for readiness. Use the reproduction in the issue to confirm the hang, then inspect readiness signaling and shutdown behavior around cancellation. Done when startup unwinds on cancellation, late readiness delivery cannot block or send to a closed channel, and deadline and runnable errors remain preserved.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Manager.Start can spin indefinitely when cancellation arrives before its cache readiness check succeeds. The wait in runnableGroup.Start handles ctx.Done() by recording a non-cancellation error, but never returns. If the cache readiness check returns false, that runnable never sends a readiness signal and the startup queue never empties. The deferred manager stop procedure is never reached.

This is reproducible with a real informer cache and no running API server. It also reproduces with a cache whose WaitForCacheSync explicitly returns false after cancellation. Both cases fail 3/3 with v0.25.0. A local source experiment that returns from the cancellation branch, removes the readiness-channel close, and makes readiness sends cancellation-aware passes both cases 3/3. The latter two changes prevent a late readiness callback from sending to a closed channel or blocking forever after startup returns.

The same cancellation loop is present in v0.25.2. The stack remains inside (*runnableGroup).Start.func1, called by (*controllerManager).Start at its cache startup step. Cancellation should let startup unwind and run the existing shutdown procedure, while preserving deadline and runnable errors.

Minimal reproduction (place in a Go module that requires sigs.k8s.io/controller-runtime v0.25.0 and matching Kubernetes dependencies, then run go test -v):

package cancellation_test

import (
    "context"
    "net/http"
    "testing"
    "time"

    "github.com/go-logr/logr"
    corev1 "k8s.io/api/core/v1"
    "k8s.io/apimachinery/pkg/api/meta"
    "k8s.io/apimachinery/pkg/runtime"
    "k8s.io/apimachinery/pkg/runtime/schema"
    "k8s.io/client-go/rest"
    "sigs.k8s.io/controller-runtime/pkg/cache"
    "sigs.k8s.io/controller-runtime/pkg/manager"
    metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
)

func TestCancellationWithRealCache(t *testing.T) {
    ctx, cancel := context.WithCancel(context.Background())
    defer cancel()
    scheme := runtime.NewScheme()
    if err := corev1.AddToScheme(scheme); err != nil { t.Fatal(err) }
    mapper := meta.NewDefaultRESTMapper([]schema.GroupVersion{corev1.SchemeGroupVersion})
    mapper.Add(corev1.SchemeGroupVersion.WithKind("ConfigMap"), meta.RESTScopeNamespace)
    opts := manager.Options{
        Scheme: scheme,
        LeaderElection: false,
        BaseContext: func() context.Context { return ctx },
        Logger: logr.Discard(),
        Metrics: metricsserver.Options{BindAddress: "0"},
        MapperProvider: func(*rest.Config, *http.Client) (meta.RESTMapper, error) {
            return mapper, nil
        },
    }
    mgr, err := manager.New(&rest.Config{Host: "http://127.0.0.1:1"}, opts)
    if err != nil { t.Fatal(err) }
    _, err = mgr.GetCache().GetInformer(ctx, &corev1.ConfigMap{}, cache.BlockUntilSynced(false))
    if err != nil { t.Fatal(err) }
    cancel()
    done := make(chan error, 1)
    go func() { done <- mgr.Start(ctx) }()
    select {
    case err := <-done:
        if err != nil { t.Fatal(err) }
    case <-time.After(time.Second):
        t.Fatal("Manager.Start did not finish after cancellation with a real informer cache")
    }
}

The one-second bound is only a regression guard. Increasing a manager shutdown deadline cannot resolve the infinite startup wait. No controller shutdown deadline, error filtering, or process termination change is needed to reproduce this.

Following CONTRIBUTING.md, reporting the proposed change here before opening a PR. Is returning from the startup cancellation branch with cancellation-aware readiness delivery the intended fix?

Lingua principale
Go
Stelle
3k
Fork
1.3k
Merge medio
1g 7h
PR unite (30g)
48

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di kubernetes-sigs/controller-runtime

Tutte le issue di kubernetes-sigs/controller-runtime

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.