From f6dcd184bd2b8da5372635a5ebfb72819413c192 Mon Sep 17 00:00:00 2001 From: Yoann Couble Date: Tue, 17 Sep 2024 14:24:24 +0200 Subject: [PATCH 1/2] fix: allow numRetries = 0 --- src/Typesense/Configuration.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Typesense/Configuration.ts b/src/Typesense/Configuration.ts index 864f685e..29495cb2 100644 --- a/src/Typesense/Configuration.ts +++ b/src/Typesense/Configuration.ts @@ -144,9 +144,9 @@ export default class Configuration { options.connectionTimeoutSeconds || options.timeoutSeconds || 5; this.healthcheckIntervalSeconds = options.healthcheckIntervalSeconds || 60; this.numRetries = - options.numRetries || - this.nodes.length + (this.nearestNode == null ? 0 : 1) || - 3; + (options.numRetries !== undefined && options.numRetries >= 0 + ? options.numRetries + : this.nodes.length + (this.nearestNode == null ? 0 : 1)) || 3; this.retryIntervalSeconds = options.retryIntervalSeconds || 0.1; this.apiKey = options.apiKey; From 9bd518422173dbd783a92cb77d4ea2af902d8402 Mon Sep 17 00:00:00 2001 From: Yoann Couble Date: Tue, 17 Sep 2024 14:31:45 +0200 Subject: [PATCH 2/2] log: retries: don't announce next retry during last try --- src/Typesense/ApiCall.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Typesense/ApiCall.ts b/src/Typesense/ApiCall.ts index c96b33c8..81ec47f4 100644 --- a/src/Typesense/ApiCall.ts +++ b/src/Typesense/ApiCall.ts @@ -313,9 +313,11 @@ export default class ApiCall { }"`, ); // this.logger.debug(error.stack) - this.logger.warn( - `Request #${requestNumber}: Sleeping for ${this.retryIntervalSeconds}s and then retrying request...`, - ); + if (numTries < this.numRetriesPerRequest + 1) { + this.logger.warn( + `Request #${requestNumber}: Sleeping for ${this.retryIntervalSeconds}s and then retrying request...`, + ); + } await this.timer(this.retryIntervalSeconds); } finally { if (abortSignal && abortListener) {