From 5c885eaa1a3c61d0a6acbd94ebceac692dad930f Mon Sep 17 00:00:00 2001 From: nai-degen <44111-khanon@users.noreply.gitgud.io> Date: Fri, 14 Apr 2023 21:13:24 -0700 Subject: [PATCH] removes duplicate keys which cause keychecker to get stuck --- src/key-management/key-checker.ts | 6 ------ src/key-management/key-pool.ts | 3 ++- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/key-management/key-checker.ts b/src/key-management/key-checker.ts index f83edb7..9e59aef 100644 --- a/src/key-management/key-checker.ts +++ b/src/key-management/key-checker.ts @@ -101,12 +101,6 @@ export class KeyChecker { // for the next check. if (key.isDisabled) { this.log.warn({ key: key.hash }, "Skipping check for disabled key."); - // If this is a startup check (key was disabled while we were waiting for - // the initial check), we need to set its lastChecked, otherwise we'll - // get stuck in a loop. - if (!key.lastChecked) { - this.updateKey(key.hash, {}); - } this.scheduleNextCheck(); return; } diff --git a/src/key-management/key-pool.ts b/src/key-management/key-pool.ts index 79d2bc3..129a9a5 100644 --- a/src/key-management/key-pool.ts +++ b/src/key-management/key-pool.ts @@ -69,6 +69,7 @@ export class KeyPool { } let bareKeys: string[]; bareKeys = keyString.split(",").map((k) => k.trim()); + bareKeys = [...new Set(bareKeys)]; for (const k of bareKeys) { const newKey = { key: k, @@ -82,7 +83,7 @@ export class KeyPool { lastUsed: 0, lastChecked: 0, promptCount: 0, - hash: crypto.createHash("sha256").update(k).digest("hex").slice(0, 6), + hash: crypto.createHash("sha256").update(k).digest("hex").slice(0, 8), }; this.keys.push(newKey);