From 0a61846b5e2101f648be0b1dba41d0c2c9ea4eac Mon Sep 17 00:00:00 2001 From: mayor Date: Wed, 14 Jan 2026 16:58:30 +0100 Subject: [PATCH] Initialize backend before search server The backend's Init() must be called before search.Init() because buildIndexes() calls storage.GetResourceStats() which requires the database connection to be established. Previously, backend.Init() was called by ResourceServer.Init() through the Lifecycle hooks, but now search.Init() runs before ResourceServer is created. Co-Authored-By: Claude Opus 4.5 --- pkg/storage/unified/sql/server.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/storage/unified/sql/server.go b/pkg/storage/unified/sql/server.go index a8baaca6fe2..91719fab2e0 100644 --- a/pkg/storage/unified/sql/server.go +++ b/pkg/storage/unified/sql/server.go @@ -159,6 +159,13 @@ func NewResourceServer(opts ServerOptions) (resource.ResourceServer, resource.Se } } + // Initialize the backend before creating search server (it needs the DB connection) + if serverOptions.Lifecycle != nil { + if err := serverOptions.Lifecycle.Init(context.Background()); err != nil { + return nil, nil, fmt.Errorf("failed to initialize backend: %w", err) + } + } + search, err := resource.NewSearchServer(opts.SearchOptions, serverOptions.Backend, opts.AccessClient, nil, opts.IndexMetrics, opts.OwnsIndexFn) if err != nil { return nil, nil, fmt.Errorf("failed to initialize search: %w", err)