You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
exportfunctioncreateRedisClusterClient(redisUrls: string[]){returnnewCluster(redisUrls,{scaleReads: 'master',// writes and reads go to master nodesslotsRefreshTimeout: 6000,clusterRetryStrategy(times: number){returnMath.min(times*50,2000);},redisOptions: {maxRetriesPerRequest: null,// retry forever until connection is open againreconnectOnError(err){// elastic cache might return READONLY when a replica node is manually promoted to primary// in that case we want to reconnectconsttargetError='READONLY';if(err.message.includes(targetError)){return2;// reconnect to the master and resend failed command}returnfalse;// default, do not reconnect},},});}
note how in redisOptions there's no "retryStrategy" since there's a clusterRetryStrategy and also the TS types say it is not allowed:
But recently I found it couldn't reconnect with this stack trace:
at TCP.callbackTrampoline (node:internal/async_hooks:130:17) |
-- | -- | --
at TCP.<anonymous> (node:net:687:12) |
at Socket.emit (node:domain:475:12) |
at Socket.emit (node:events:390:28) |
at Object.onceWrapper (node:events:510:26) |
at Socket.<anonymous> (xxx/node_modules/ioredis/built/redis/event_handler.js:160:20) |
at close (xxx/node_modules/ioredis/built/redis/event_handler.js:189:14) |
at EventEmitter.flushQueue (xxx/node_modules/ioredis/built/Redis.js:614:30) |
at Command.command.reject (xxx/node_modules/ioredis/built/cluster/index.js:362:23) |
at EventEmitter.handleError (xxx/node_modules/ioredis/built/cluster/index.js:508:38) |
Error: Too many Cluster redirections. Last error: Error: Connection is closed.
particularly of interest is this line
at Socket.<anonymous> (xxx/node_modules/ioredis/built/redis/event_handler.js:160:20) |
if (typeof self.options.retryStrategy !== "function") {
debug("skip reconnecting because `retryStrategy` is not a function");
return close();
}
so my question is, are the types wrong (and therefore retryStrategy should be inside the cluster client options) or is the code wrong and it should have re-tried as clusterRetryStrategy mandates?
Also it confuses me that the docs state
By default, ioredis will try to reconnect when the connection to Redis is lost except when the connection is closed manually by redis.disconnect() or redis.quit().
but that piece of code makes it look like it won't unless that function is there?
The text was updated successfully, but these errors were encountered:
(node:6) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [Socket]. Use emitter.setMaxListeners() to increase limit
since that also happened in that disconnection, but I guess that might be a totally different issue
javiergonzalezGenially
changed the title
The redis cluster couldn't reconnect because retryStrategy is not set, but the TS types says that's not allowed
The redis cluster couldn't reconnect because retryStrategy is not set, but the TS types state that's not allowed
Apr 21, 2023
javiergonzalezGenially
changed the title
The redis cluster couldn't reconnect because retryStrategy is not set, but the TS types state that's not allowed
Cluster client couldn't reconnect because retryStrategy is not set, but the TS types state that's not allowed
Apr 21, 2023
After looking more deeply at ioRedis code my hunch is that it couldn't reconnect on the timeout given by retryDelayOnFailover (100) * maxRedirections (16) which is just 1600ms (which seems quite low)
I have a cluster client configured like this:
note how in redisOptions there's no "retryStrategy" since there's a clusterRetryStrategy and also the TS types say it is not allowed:
But recently I found it couldn't reconnect with this stack trace:
particularly of interest is this line
so my question is, are the types wrong (and therefore retryStrategy should be inside the cluster client options) or is the code wrong and it should have re-tried as clusterRetryStrategy mandates?
Also it confuses me that the docs state
but that piece of code makes it look like it won't unless that function is there?
The text was updated successfully, but these errors were encountered: