From 39ff4021e3a117064750c9aa6bb5b8fb5c5952e7 Mon Sep 17 00:00:00 2001 From: zeevdr Date: Sun, 24 May 2026 15:28:26 +0300 Subject: [PATCH] fix(client): clear serverInfoPromise on rejection to allow retry The cached promise was never cleared on failure, so every subsequent call received the same rejected promise forever. The .catch handler now resets serverInfoPromise to undefined on rejection, letting callers retry successfully. Closes #53 Co-Authored-By: Claude --- src/client.ts | 3 +++ test/client.test.ts | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/client.ts b/src/client.ts index 45ba11f..5eb6b3a 100644 --- a/src/client.ts +++ b/src/client.ts @@ -100,6 +100,9 @@ export class ConfigClient { get serverInfo(): Promise { if (this.serverInfoPromise === undefined) { this.serverInfoPromise = this.fetchServerInfo(); + this.serverInfoPromise.catch(() => { + this.serverInfoPromise = undefined; + }); } return this.serverInfoPromise; } diff --git a/test/client.test.ts b/test/client.test.ts index e267cd3..6a76c6e 100644 --- a/test/client.test.ts +++ b/test/client.test.ts @@ -322,6 +322,27 @@ describe("ConfigClient", () => { await expect(client.serverInfo).rejects.toThrow(UnavailableError); }); + it("clears cached promise on rejection so callers can retry", async () => { + serverStub.getServerInfo + .mockImplementationOnce( + (_req: unknown, _meta: unknown, _opts: unknown, cb: (...args: unknown[]) => void) => { + cb(makeServiceError(status.UNAVAILABLE, "server down")); + }, + ) + .mockImplementationOnce( + (_req: unknown, _meta: unknown, _opts: unknown, cb: (...args: unknown[]) => void) => { + cb(null, { version: "0.9.0", commit: "def456", features: {} }); + }, + ); + + await expect(client.serverInfo).rejects.toThrow(UnavailableError); + // allow the .catch cleanup to run + await Promise.resolve(); + const info = await client.serverInfo; + expect(info.version).toBe("0.9.0"); + expect(serverStub.getServerInfo).toHaveBeenCalledTimes(2); + }); + it("exposes deprecated serverVersion alias", async () => { serverStub.getServerInfo.mockImplementation( (_req: unknown, _meta: unknown, _opts: unknown, cb: (...args: unknown[]) => void) => {