From f4b3c12111afb87b9df76e159f378d5c9bef9206 Mon Sep 17 00:00:00 2001 From: Nathan Friedly Date: Fri, 1 Dec 2023 07:47:37 -0500 Subject: [PATCH] bump init timeout to 10s Apparently workers can take over a second to initialize in some environments, leading to unnecessary error messages Fixes #2 --- source/worker.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/source/worker.ts b/source/worker.ts index 99d660b..9eb707d 100644 --- a/source/worker.ts +++ b/source/worker.ts @@ -89,7 +89,7 @@ export class ClusterMemoryStoreWorker implements Store { } cluster.worker.on('message', this.onMessage.bind(this)) - return this.send('init', [{ windowMs: this.windowMs }]).catch( + return this.send('init', [{ windowMs: this.windowMs }], 10 * 1000).catch( (error: any) => { console.error(`${errorPrefix} failed to initialize`, error) }, @@ -131,11 +131,14 @@ export class ClusterMemoryStoreWorker implements Store { await this.send('resetKey', [key]) } - private async send(command: Command, args: any[]): Promise { + private async send( + command: Command, + args: any[], + timelimit = 1000, + ): Promise { debug('Sending command %s with args %o', command, args) return new Promise((resolve, reject) => { const requestId = this.currentRequestId++ - const timelimit = 1000 const timeoutId = setTimeout(() => { reject( new Error(