Skip to content

Commit

Permalink
bump init timeout to 10s
Browse files Browse the repository at this point in the history
Apparently workers can take over a second to initialize in some environments, leading to unnecessary error messages

Fixes #2
  • Loading branch information
nfriedly committed Dec 7, 2023
1 parent fa68901 commit f4b3c12
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions source/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
Expand Down Expand Up @@ -131,11 +131,14 @@ export class ClusterMemoryStoreWorker implements Store {
await this.send('resetKey', [key])
}

private async send(command: Command, args: any[]): Promise<any> {
private async send(
command: Command,
args: any[],
timelimit = 1000,
): Promise<any> {
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(
Expand Down

0 comments on commit f4b3c12

Please sign in to comment.