The connection is already closed error
I am using the next code to maintain connection errors and reconnections.
self.client = redis.createClient(self.cfg.port, self.cfg.host, {retry_strategy: function (options) {
if (options.error) {
if (options.error.code === 'ECONNREFUSED') {
// End reconnecting on a specific error and flush all commands with a individual error
return new Error('The server refused the connection');
}
if (options.error.code === 'ECONNRESET') {
return new Error('The server reset the connection');
}
if (options.error.code === 'ETIMEDOUT') {
return new Error('The server timeouted the connection');
}
}
if (options.total_retry_time > 1000 * 60 * 60) {
// End reconnecting after a specific timeout and flush all commands with a individual error
return new Error('Retry time exhausted');
}
if (options.attempt > 5) {
// End reconnecting with built in error
return new Error('Retry attempts ended');
}
// reconnect after
return 1000;
}});
self.client.on('error', function (err) {
log.error({err: err}, 'EventParser.redis.client error: %s', err);
process.exit(1);
});
But recently I received 28Mb logs of trying to execute SMEMBERS command on a closed connection. retry_strategy was not triggered. Another workers which use the same redis connection did not produce any errors at all.
{"name":"myworker","hostname":"2cc64ce4ff8a","pid":30450,"level":40,"err":{"message":"SMEMBERS can't be processed. The connection is already closed.","name":"AbortError","stack":"AbortError: SMEMBERS can't be processed. The connection is already closed.\n at handle_offline_command (/node_modules/redis/index.js:843:15)\n at RedisClient.internal_send_command (/node_modules/redis/index.js:873:9)\n at RedisClient.smembers (/node_modules/redis/lib/commands.js:62:25)\n at bound (/node_modules/q/q.js:1942:29)\n at Promise.apply (/node_modules/q/q.js:1165:26)\n at Promise.promise.promiseDispatch (/node_modules/q/q.js:788:41)\n at /node_modules/q/q.js:1391:14\n at runSingle (/node_modules/q/q.js:137:13)\n at flush (/node_modules/q/q.js:125:13)\n at _combinedTickCallback (internal/process/next_tick.js:67:7)\n at process._tickDomainCallback (internal/process/next_tick.js:122:9)","code":"NR_CLOSED"},"msg":"MyWorker.processData error: AbortError: SMEMBERS can't be processed. The connection is already closed.","time":"2016-07-22T12:45:02.600Z","v":0}
- Version: node_redis v.2.6.2 and Redis 3.0.7
- Platform: Node.js v5.10.1 on Ubuntu 14.04.4 LTS
- Description: Already closed connection does not trigger retry_strategy handlers
Looks like I'm experiencing the same problem. Getting The connection is already closed having retry_strategy in options
hey guys, any suggestions on how to resolve it?
Please if anyone can update on some settings we are missing
let me check how to import "self.client = redis.createClient()" from you code. in my image: ` yourNodeModuleForRedis.js -- self.client = redis.createClient()
you are importing "yourNodeModuleForRedis" to another module as below : callingRedis.js -- var redis = require("yourNodeModuleForRedis") `
then you may meet "PUBLISH(or SUBSCRIBE) can't be processed. The connection is already closed"
I believe I'm hitting this issue when upgrading ElastiCache. Connection dies, and no notification comes through. Connection just stops working. locking up the entire node process. Am I missing something else simple to fix this, or I am indeed seeing the same?
Did anyone have any luck resolving this issue?
recently I've got this error and can't understand how options.error can be null
if (options.error.code === 'ECONNREFUSED') { ^
TypeError: Cannot read property 'code' of null at Object.self.client.redis.createClient.retry_strategy (/var/daemon/script.js:86:24) at RedisClient.connection_gone (/node_modules/redis/index.js:606:41) at Socket.
(/node_modules/redis/index.js:286:14) at Socket.g (events.js:273:16) at emitNone (events.js:85:20) at Socket.emit (events.js:179:7) at endReadableNT (_stream_readable.js:906:12) at nextTickCallbackWith2Args (node.js:474:9) at process._tickCallback (node.js:388:17)
If the connection is closed the client will not reconnect at all anymore. Therefore the retryStrategy will not be triggered either.
As soon as you return a non number from the retryStrategy no retry will happen anymore and all further commands will be rejected with the known error message.
@pavelsc you have a different issue, please check if there's a error currently.