Address review feedback for waitForReady and helpers

Change lastError type to unknown to match catch clause semantics,
and disconnect failed Keyv instances in attemptKeyvConnection to
avoid leaking sockets/handles during readiness polling.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Made-with: Cursor
This commit is contained in:
Patrik Oldsberg
2026-04-13 22:53:29 +02:00
parent f44c6bd265
commit fb9efc3e28
2 changed files with 17 additions and 5 deletions
+16 -4
View File
@@ -31,10 +31,22 @@ export async function attemptKeyvConnection(
await waitForReady(async () => {
const store = createStore(connection);
keyv = new Keyv({ store });
const value = uuid();
await keyv.set('test', value);
return (await keyv.get('test')) === value;
const attemptKeyv = new Keyv({ store });
let succeeded = false;
try {
const value = uuid();
await attemptKeyv.set('test', value);
succeeded = (await attemptKeyv.get('test')) === value;
if (succeeded) {
keyv = attemptKeyv;
}
return succeeded;
} finally {
if (!succeeded) {
await attemptKeyv.disconnect();
}
}
}, label);
return keyv!;
@@ -31,7 +31,7 @@ export async function waitForReady(
): Promise<void> {
const startTime = Date.now();
let lastError: Error | undefined;
let lastError: unknown;
let attempts = 0;
for (;;) {
attempts += 1;