question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Connection is Closed

See original GitHub issue

ioRedis@4.9.0 Redis Server Version: 5 Using Redis sentinel on production.

Error: Connection is closed. at Redis.sendCommand (/nodeApi/node_modules/ioredis/built/redis.js:552:24)

I have specified the retryStragey, which is working if any redis node(master) goes down and I am assuming it should work for this case too. Or do I need to specify some other option?

var redis = require('ioredis'),
client = Promise.promisifyAll(redis.createClient( {
	sentinels: config.redis.endpoints,
	name: config.redis.masterName,
	prefix: config.database.redisPrefix,
	pass: config.database.redisPassword,
	role:"slave",
	retry_strategy: function (options) {
		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.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.times_connected > 10) {
			// End reconnecting with built in error
			return undefined;
		}
		// reconnect after
		return Math.max(options.attempt * 100, 500);
	}
})),

client.on("error", function (err) {
	console.log("Error " + err);
});

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

14reactions
luincommented, Jul 14, 2019

Just set retryStrategy to null will do the trick:

const redis = new Redis(redisDsn, {
  retryStrategy: null
});

redis.on('end', () => {
  log.warn('shutting down service due to lost Redis connection');

  lightship.shutdown();
});
2reactions
luincommented, Jul 14, 2019

@gajus Actually it’s documented https://github.com/luin/ioredis#auto-reconnect, but in another format:

retryStrategy is a function that will be called when the connection is lost. The argument times means this is the nth reconnection being made and the return value represents how long (in ms) to wait to reconnect. When the return value isn’t a number, ioredis will stop trying to reconnect, and the connection will be lost forever if the user doesn’t call redis.connect() manually.

So besides retryStrategy: null, you can also write retryStrategy() { return false }. The documentation needs a restructure anyway as it becomes too long to read.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java.sql.SQLException: Connection is closed - Stack Overflow
You might have called for closeConnection() method after select statement.So an exception is thrown at runtime when it tried to execute the ...
Read more >
How to deal with closed connections in database pool
This article explains how to overcome the "connection is closed" error that sometimes is seen on the mule logs when connecting to a...
Read more >
Cause: java.sql.SQLException: Connection is closed - Flowable
My Sprin Boot Application got exception which is “Cause: java.sql.SQLException: Connection is closed”,I think this is the same problem to ...
Read more >
How To Fix "ERR_CONNECTION_CLOSED" in Chrome (13 ...
The ERR_CONNECTION_CLOSED message is essentially telling you that Chrome tried to make this connection, but something went wrong with your ...
Read more >
Handling java.sql.SQLRecoverableException: Closed ...
This error message indicates that the connection used by the backup task (or any other long-running operation that relies on a single database ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found