Skip to content

A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search

fix(plugins): don't cache a rejected init promise in the meilisearch providers

Mohamed Bassem64ec6cbcf296
diff --git a/packages/plugins/search-meilisearch/src/index.ts b/packages/plugins/search-meilisearch/src/index.ts
index e66533b3..a2d9f554 100644
--- a/packages/plugins/search-meilisearch/src/index.ts
+++ b/packages/plugins/search-meilisearch/src/index.ts
@@ -148,9 +148,15 @@ export class MeiliSearchProvider implements PluginProvider<SearchIndexClient> {
}
this.initPromise = this.initClient();
- const client = await this.initPromise;
- this.initPromise = undefined;
- return client;
+ try {
+ return await this.initPromise;
+ } finally {
+ // Always clear the in-flight promise, including when init rejected.
+ // Otherwise a transient failure (e.g. meilisearch restarting) would be
+ // cached as a permanently rejected promise and every later call would
+ // replay it for the lifetime of the process.
+ this.initPromise = undefined;
+ }
}
private async initClient(): Promise<SearchIndexClient | null> {
diff --git a/packages/plugins/vectorstore-meilisearch/src/index.ts b/packages/plugins/vectorstore-meilisearch/src/index.ts
index 68602c51..901bc9a5 100644
--- a/packages/plugins/vectorstore-meilisearch/src/index.ts
+++ b/packages/plugins/vectorstore-meilisearch/src/index.ts
@@ -175,9 +175,15 @@ export class MeiliSearchVectorProvider implements PluginProvider<VectorStoreClie
}
this.initPromise = this.initClient();
- const client = await this.initPromise;
- this.initPromise = undefined;
- return client;
+ try {
+ return await this.initPromise;
+ } finally {
+ // Always clear the in-flight promise, including when init rejected.
+ // Otherwise a transient failure (e.g. meilisearch restarting) would be
+ // cached as a permanently rejected promise and every later call would
+ // replay it for the lifetime of the process.
+ this.initPromise = undefined;
+ }
}
private async initClient(): Promise<VectorStoreClient | null> {
diff --git a/packages/trpc/routers/admin.ts b/packages/trpc/routers/admin.ts
index a47f7226..479b983b 100644
--- a/packages/trpc/routers/admin.ts
+++ b/packages/trpc/routers/admin.ts
@@ -660,38 +660,45 @@ export const adminAppRouter = router({
error?: string;
} = { configured: false, connected: false };
- const searchClient = await getSearchClient();
- searchEngineStatus.configured = searchClient !== null;
-
- if (searchClient) {
- const pluginName = PluginManager.getPluginName(PluginType.Search);
- if (pluginName) {
- searchEngineStatus.pluginName = pluginName;
- }
- try {
+ // Resolving a client can itself throw (the provider connects lazily on
+ // first use), so it has to be inside the try as well -- otherwise one
+ // unreachable backend takes down this whole endpoint instead of just
+ // reporting itself as disconnected.
+ const searchPluginName = PluginManager.getPluginName(PluginType.Search);
+ if (searchPluginName) {
+ searchEngineStatus.pluginName = searchPluginName;
+ }
+ try {
+ const searchClient = await getSearchClient();
+ searchEngineStatus.configured = searchClient !== null;
+ if (searchClient) {
await searchClient.search({ query: "", limit: 1 });
searchEngineStatus.connected = true;
- } catch (error) {
- searchEngineStatus.error =
- error instanceof Error ? error.message : "Unknown error";
}
+ } catch (error) {
+ // A provider is registered (that's the only way getClient can throw),
+ // so it is configured -- it just can't be reached right now.
+ searchEngineStatus.configured = true;
+ searchEngineStatus.error =
+ error instanceof Error ? error.message : "Unknown error";
}
- const vectorStoreClient = await getVectorStoreClient();
- vectorStoreStatus.configured = vectorStoreClient !== null;
-
- if (vectorStoreClient) {
- const pluginName = PluginManager.getPluginName(PluginType.VectorStore);
- if (pluginName) {
- vectorStoreStatus.pluginName = pluginName;
- }
-
- try {
+ const vectorStorePluginName = PluginManager.getPluginName(
+ PluginType.VectorStore,
+ );
+ if (vectorStorePluginName) {
+ vectorStoreStatus.pluginName = vectorStorePluginName;
+ }
+ try {
+ const vectorStoreClient = await getVectorStoreClient();
+ vectorStoreStatus.configured = vectorStoreClient !== null;
+ if (vectorStoreClient) {
vectorStoreStatus.connected = await vectorStoreClient.getHealth();
- } catch (error) {
- vectorStoreStatus.error =
- error instanceof Error ? error.message : "Unknown error";
}
+ } catch (error) {
+ vectorStoreStatus.configured = true;
+ vectorStoreStatus.error =
+ error instanceof Error ? error.message : "Unknown error";
}
browserStatus.configured =