Search code examples
javaredisnullpointerexceptionthreadpoolexecutorjedis

null pointer exception in jedis


My log is full of this exception from Jedis, even that is log level info I cannot ignore it

load technicians buffer took 2942 miliseconds : java.lang.NullPointerException at redis.clients.jedis.BinaryJedis.ping(BinaryJedis.java:187) at redis.clients.jedis.JedisFactory.validateObject(JedisFactory.java:152) at org.apache.commons.pool2.impl.GenericObjectPool.returnObject(GenericObjectPool.java:534) at redis.clients.jedis.util.Pool.returnResourceObject(Pool.java:68) at redis.clients.jedis.JedisPool.returnResource(JedisPool.java:251) at redis.clients.jedis.Jedis.close(Jedis.java:3505) at com.puls.availability.services.AvailabilityServiceImpl.getAvailabilityBufferPerVertical(AvailabilityServiceImpl.java:360) at java.base/java.lang.Thread.run(Thread.java:834) java.lang.NullPointerException at redis.clients.jedis.BinaryJedis.quit(BinaryJedis.java:255) at redis.clients.jedis.JedisFactory.destroyObject(JedisFactory.java:99) at org.apache.commons.pool2.impl.GenericObjectPool.destroy(GenericObjectPool.java:927) at org.apache.commons.pool2.impl.GenericObjectPool.evict(GenericObjectPool.java:768) at org.apache.commons.pool2.impl.BaseGenericObjectPool$Evictor.run(BaseGenericObjectPool.java:1138) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305) at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:834) java.lang.NullPointerException at redis.clients.jedis.BinaryJedis.quit(BinaryJedis.java:255) at redis.clients.jedis.JedisFactory.destroyObject(JedisFactory.java:99) at org.apache.commons.pool2.impl.GenericObjectPool.destroy(GenericObjectPool.java:927) at org.apache.commons.pool2.impl.GenericObjectPool.evict(GenericObjectPool.java:768) at org.apache.commons.pool2.impl.BaseGenericObjectPool$Evictor.run(BaseGenericObjectPool.java:1138) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305) at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:834) java.lang.NullPointerException at redis.clients.jedis.BinaryJedis.quit(BinaryJedis.java:255) at redis.clients.jedis.JedisFactory.destroyObject(JedisFactory.java:99) at org.apache.commons.pool2.impl.GenericObjectPool.destroy(GenericObjectPool.java:927) at org.apache.commons.pool2.impl.GenericObjectPool.evict(GenericObjectPool.java:768) at org.apache.commons.pool2.impl.BaseGenericObjectPool$Evictor.run(BaseGenericObjectPool.java:1138) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305) at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:834)

My pool configurations are:

    final JedisPoolConfig poolConfig = new JedisPoolConfig();
    poolConfig.setMaxTotal(128);
    poolConfig.setMaxIdle(128);
    poolConfig.setMinIdle(16);
    poolConfig.setTestOnBorrow(true);
    poolConfig.setTestOnReturn(true);
    poolConfig.setTestWhileIdle(true);
    poolConfig.setMinEvictableIdleTimeMillis(Duration.ofSeconds(60).toMillis());
    poolConfig.setTimeBetweenEvictionRunsMillis(Duration.ofSeconds(30).toMillis());
    poolConfig.setNumTestsPerEvictionRun(3);

and this is my jedispool creation:

new JedisPool(poolConfig, host, port, 1000);

Where is it coming from?


Solution

  • What makes this issue hard to solve is the hidden part of the exception,

    The exception should look like :

    load technicians buffer took 2942 miliseconds : java.lang.NullPointerException 
    at co.elastic.apm.agent.redis.RedisSpanUtils.createRedisSpan(RedisSpanUtils.java:xxx)
    at redis.clients.jedis.BinaryJedis.ping(BinaryJedis.java:187) 
    at redis.clients.jedis.JedisFactory.validateObject(JedisFactory.java:152) 
    at org.apache.commons.pool2.impl.GenericObjectPool.returnObject(GenericObjectPool.java:534) 
    at redis.clients.jedis.util.Pool.returnResourceObject(Pool.java:68) 
    at redis.clients.jedis.JedisPool.returnResource(JedisPool.java:251) 
    at redis.clients.jedis.Jedis.close(Jedis.java:3505) 
    at .....
    

    This line is missing from the original exception : co.elastic.apm.agent.redis.RedisSpanUtils.createRedisSpan(RedisSpanUtils.java:xxx)

    The exception is occurred in the java APM agent of Elastic, but the exception is not traced because the agent is using the Instrumentation API of Java.

    While waiting for Elastic to fix the issue you can disable the agent from listening on Redis requests.