I have setup a standalone Redis server (v 7.0.4). I have configured a password for it using requirepass
config. I am using Jedis (v 4.2.0) as the client.
Following is the code for creating JedisPool to connect with Redis -
public JedisConnectionPool(final JedisPoolConfig poolConfig, final String host, int port, int timeout, final String password) {
this.pool = new JedisPool(poolConfig, host, port, timeout, password);
}
I have a sequence of updates coming together, some updates are completed successfully, then I start getting following error -
Caused by: redis.clients.jedis.exceptions.JedisDataException: NOAUTH Authentication required.
at redis.clients.jedis.Protocol.processError(Protocol.java:96) ~[jedis-4.2.0.jar:na]
at redis.clients.jedis.Protocol.process(Protocol.java:137) ~[jedis-4.2.0.jar:na]
at redis.clients.jedis.Protocol.read(Protocol.java:192) ~[jedis-4.2.0.jar:na]
at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:316) ~[jedis-4.2.0.jar:na]
at redis.clients.jedis.Connection.getOne(Connection.java:298) ~[jedis-4.2.0.jar:na]
at redis.clients.jedis.Connection.executeCommand(Connection.java:123) ~[jedis-4.2.0.jar:na]
at redis.clients.jedis.Jedis.get(Jedis.java:4901) ~[jedis-4.2.0.jar:na]
This error occurs multiple times, then following error comes -
2022-11-23 04:04:39.124 ERROR 62960 --- [ns-pool-evictor] redis.clients.jedis.JedisFactory : Error while validating pooled Jedis object.
redis.clients.jedis.exceptions.JedisDataException: NOAUTH Authentication required.
at redis.clients.jedis.Protocol.processError(Protocol.java:96) ~[jedis-4.2.0.jar:na]
at redis.clients.jedis.Protocol.process(Protocol.java:137) ~[jedis-4.2.0.jar:na]
at redis.clients.jedis.Protocol.read(Protocol.java:192) ~[jedis-4.2.0.jar:na]
at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:316) ~[jedis-4.2.0.jar:na]
at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:243) ~[jedis-4.2.0.jar:na]
at redis.clients.jedis.Jedis.ping(Jedis.java:356) ~[jedis-4.2.0.jar:na]
at redis.clients.jedis.JedisFactory.validateObject(JedisFactory.java:211) ~[jedis-4.2.0.jar:na]
at org.apache.commons.pool2.impl.GenericObjectPool.evict(GenericObjectPool.java:745) ~[commons-pool2-2.11.1.jar:2.11.1]
at org.apache.commons.pool2.impl.BaseGenericObjectPool$Evictor.run(BaseGenericObjectPool.java:160) ~[commons-pool2-2.11.1.jar:2.11.1]
at org.apache.commons.pool2.impl.EvictionTimer$WeakRunner.run(EvictionTimer.java:113) ~[commons-pool2-2.11.1.jar:2.11.1]
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) ~[na:na]
at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305) ~[na:na]
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[na:na]
at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
After this the remaining updates are updates successfully to Redis.
As the same JedisPool is used to get Jedis Connection objects, I don't understand why there is NOAUTH error for some updates while others are completed successfully.
Can someone help resolve this?
One of the possibilities is that the underlying socket of the Jedis
object was actually closed and so its AUTHed state is cleared. This may happen if the Jedis
object borrowed from JedisPool
is closed twice (or multiple times). Because first close()
would return the object to the pool but subsequent close()
would cause the underlying socket object to be closed.
Check of the Jedis
object borrowed from JedisPool
is closed multiple times. If you use try-with-resources, one close operation could be hidden, e.g.
try (Jedis jedis = this.pool.getResource()) {
// operations by jedis
jedis.close(); // <-- first, visible close
} // <-- second, hidden close