Skip to content

Commit 76c10e4

Browse files
zeevdrclaude
andauthored
fix(client): clear serverInfoPromise on rejection to allow retry (#84)
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 <noreply@anthropic.com>
1 parent 626acc0 commit 76c10e4

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

src/client.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ export class ConfigClient {
100100
get serverInfo(): Promise<ServerInfo> {
101101
if (this.serverInfoPromise === undefined) {
102102
this.serverInfoPromise = this.fetchServerInfo();
103+
this.serverInfoPromise.catch(() => {
104+
this.serverInfoPromise = undefined;
105+
});
103106
}
104107
return this.serverInfoPromise;
105108
}

test/client.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,27 @@ describe("ConfigClient", () => {
322322
await expect(client.serverInfo).rejects.toThrow(UnavailableError);
323323
});
324324

325+
it("clears cached promise on rejection so callers can retry", async () => {
326+
serverStub.getServerInfo
327+
.mockImplementationOnce(
328+
(_req: unknown, _meta: unknown, _opts: unknown, cb: (...args: unknown[]) => void) => {
329+
cb(makeServiceError(status.UNAVAILABLE, "server down"));
330+
},
331+
)
332+
.mockImplementationOnce(
333+
(_req: unknown, _meta: unknown, _opts: unknown, cb: (...args: unknown[]) => void) => {
334+
cb(null, { version: "0.9.0", commit: "def456", features: {} });
335+
},
336+
);
337+
338+
await expect(client.serverInfo).rejects.toThrow(UnavailableError);
339+
// allow the .catch cleanup to run
340+
await Promise.resolve();
341+
const info = await client.serverInfo;
342+
expect(info.version).toBe("0.9.0");
343+
expect(serverStub.getServerInfo).toHaveBeenCalledTimes(2);
344+
});
345+
325346
it("exposes deprecated serverVersion alias", async () => {
326347
serverStub.getServerInfo.mockImplementation(
327348
(_req: unknown, _meta: unknown, _opts: unknown, cb: (...args: unknown[]) => void) => {

0 commit comments

Comments
 (0)