From ccdac30f6098625db6d8143a216f6a53a6715e55 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Thu, 3 Sep 2026 11:52:40 +0000 Subject: [PATCH] fix(jsoncs3): wait for init before asserting the migration timeout New() initializes the metadata storage in a background goroutine. The CleanupStaleShares spec started its 1ms context right after New(), so under load the context expired during initialization and the manager returned "not yet initialized" instead of the migration timeout. Expose Ready() and wait for it before starting the timeout context. --- pkg/share/manager/jsoncs3/jsoncs3.go | 6 ++++++ pkg/share/manager/jsoncs3/jsoncs3_test.go | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/share/manager/jsoncs3/jsoncs3.go b/pkg/share/manager/jsoncs3/jsoncs3.go index 021b541bd9..2e90b062ea 100644 --- a/pkg/share/manager/jsoncs3/jsoncs3.go +++ b/pkg/share/manager/jsoncs3/jsoncs3.go @@ -340,6 +340,12 @@ func (m *Manager) initialize(ctx context.Context) error { return nil } +// Ready returns a channel that is closed once the background initialization +// goroutine has successfully connected to the metadata storage. +func (m *Manager) Ready() <-chan struct{} { + return m.ready +} + // waitForInit blocks until the background initialization goroutine has // successfully completed, or until ctx is cancelled. func (m *Manager) waitForInit(ctx context.Context) error { diff --git a/pkg/share/manager/jsoncs3/jsoncs3_test.go b/pkg/share/manager/jsoncs3/jsoncs3_test.go index 4620a69d26..fbb4563a49 100644 --- a/pkg/share/manager/jsoncs3/jsoncs3_test.go +++ b/pkg/share/manager/jsoncs3/jsoncs3_test.go @@ -1163,7 +1163,13 @@ var _ = Describe("CleanupStaleShares", func() { m, err := jsoncs3.New(storage, nil, nil, 0, nil, 0) Expect(err).ToNot(HaveOccurred()) - ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond) + // New initializes the metadata storage in the background. Wait for that + // to finish, otherwise the context below can expire while the manager is + // still initializing and CleanupStaleShares reports that instead of the + // migration timeout. + Eventually(m.Ready(), 10*time.Second).Should(BeClosed()) + + ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond) defer cancel() err = m.CleanupStaleShares(ctx)