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 <noreply@anthropic.com>
This commit is contained in:
mayorandClaude Opus 4.5 authored and Rafael Paulovic committed 2026-01-14 16:58:30 +01:00
1 parent 785cc739ee
commit 0a61846b5e
1 file changed
+7
+7
View File
@@ -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)