redis / jedis

Redis Java client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

redis.clients.jedis.exceptions.JedisConnectionException: Unexpected end of stream. - issue with jedis 5.1.0

TrainingByCoding opened this issue · comments

NOTE : It works fine with Jedis 2.10.0 , but issue started when upgraded the jedis to 4.4.6 or 5.1.0

POM dependencies are below -

<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <spring-boot.version>3.0.4</spring-boot.version>
        <jackson.version>2.16.0</jackson.version>
        <hadoop.version>3.3.6</hadoop.version>
    </properties>
<dependency>
            <groupId>org.springframework.retry</groupId>
            <artifactId>spring-retry</artifactId>
            <version>1.3.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>6.0.6</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>5.2.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.bettercloud</groupId>
            <artifactId>vault-java-driver</artifactId>
            <version>5.0.0</version> 
        </dependency>
 <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-pool2</artifactId>
            <version>2.12.0</version>
        </dependency> 
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.14.0</version>
        </dependency> 
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-text</artifactId>
            <version>1.11.0</version>
        </dependency>
 <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-aws</artifactId>
            <version>${hadoop.version}</version>
        </dependency> 
**<dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>5.1.0</version>
        </dependency>**

Jedis configuration in Java code -
private int CONNECTION_TIMEOUT=5000;
private JedisPoolConfig buildPoolConfig() {
final JedisPoolConfig poolConfig = new JedisPoolConfig();
poolConfig.setSoftMinEvictableIdleDuration(Duration.ofSeconds(60));
poolConfig.setMaxTotal(256);
poolConfig.setMaxIdle(256);
poolConfig.setMinIdle(32);
poolConfig.setTestOnBorrow(true);
poolConfig.setTestWhileIdle(true);
poolConfig.setMinEvictableIdleDuration(Duration.ofSeconds(60));
poolConfig.setTimeBetweenEvictionRuns(Duration.ofSeconds(30));
poolConfig.setNumTestsPerEvictionRun(3);
return poolConfig;
}

@bean(name = "jedistestpool")
protected JedisPool testPool() {
JedisPool jedisPool = null;
try {
jedisPool = new JedisPool(poolConfig, REDIS_HOSTNAME, REDIS_PORT,CONNECTION_TIMEOUT);
} catch (Exception e) {
System.out.println("Error in testPool-" + e.getMessage());
}
return jedisPool;
}

code where connection pool used

@Autowired
  @Qualifier("jedistestpool")
  JedisPool testPool;

   @Retryable(value = {Exception.class}, maxAttempts = 3, backoff = @Backoff(delay = 30000))
  public void setExpire(List<Map<byte[], Map<byte[], byte[]>>> list, int timeout, String cache) {
      JedisPool jedisPool = null;
      Jedis jedis = null;
      try {
          switch (cache) { 
              case Constants.TEST:
                  jedisPool = testPool;
                  break; 
          }
          **jedis = jedisPool.getResource(); /// i am getting error from here**
          Pipeline pipelined = jedis.pipelined();
          Iterator<Map<byte[], Map<byte[], byte[]>>> iterator = list.iterator();
          while (iterator.hasNext()) {
              Map<byte[], Map<byte[], byte[]>> region = iterator.next();
              for (Map.Entry<byte[], Map<byte[], byte[]>> entry : region.entrySet()) {
                  pipelined.expire(entry.getKey(), (int) timeout);
              }
          }
          pipelined.sync();

      } catch (Exception e) {
          throw e;         
  }

Error message
`ERROR 19128 --- [ns-pool-evictor] redis.clients.jedis.JedisFactory : Error while validating pooled Jedis object.

redis.clients.jedis.exceptions.JedisConnectionException: Unexpected end of stream.
at redis.clients.jedis.util.RedisInputStream.ensureFill(RedisInputStream.java:248) ~[jedis-5.1.0.jar:na]
at redis.clients.jedis.util.RedisInputStream.readByte(RedisInputStream.java:47) ~[jedis-5.1.0.jar:na]
at redis.clients.jedis.Protocol.process(Protocol.java:135) ~[jedis-5.1.0.jar:na]
at redis.clients.jedis.Protocol.read(Protocol.java:221) ~[jedis-5.1.0.jar:na]
at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:350) ~[jedis-5.1.0.jar:na]
at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:268) ~[jedis-5.1.0.jar:na]
at redis.clients.jedis.Jedis.ping(Jedis.java:339) ~[jedis-5.1.0.jar:na]
at redis.clients.jedis.JedisFactory.validateObject(JedisFactory.java:198) ~[jedis-5.1.0.jar:na]
at org.apache.commons.pool2.impl.GenericObjectPool.evict(GenericObjectPool.java:748) ~[commons-pool2-2.12.0.jar:2.12.0]
at org.apache.commons.pool2.impl.BaseGenericObjectPool$Evictor.run(BaseGenericObjectPool.java:162) ~[commons-pool2-2.12.0.jar:2.12.0]
at org.apache.commons.pool2.impl.EvictionTimer$WeakRunner.run(EvictionTimer.java:115) ~[commons-pool2-2.12.0.jar:2.12.0]
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]
`

@yangbodong22011
If I am not wrong, you faced the same issue in 2022, can you please have a look at this issue?

@yangbodong22011 If I am not wrong, you faced the same issue in 2022, can you please have a look at this issue?

I don't remember. Do you have any links or information? from your code, you should call jedis.close() at finally.

try {
          switch (cache) { 
              case Constants.TEST:
                  jedisPool = testPool;
                  break; 
          }
          **jedis = jedisPool.getResource(); /// i am getting error from here**
          Pipeline pipelined = jedis.pipelined();
          Iterator<Map<byte[], Map<byte[], byte[]>>> iterator = list.iterator();
          while (iterator.hasNext()) {
              Map<byte[], Map<byte[], byte[]>> region = iterator.next();
              for (Map.Entry<byte[], Map<byte[], byte[]>> entry : region.entrySet()) {
                  pipelined.expire(entry.getKey(), (int) timeout);
              }
          }
          pipelined.sync();

      } catch (Exception e) {
          throw e;         
      } finally {
          if (jedis != null) {
              jedis.close();
          }
      }

**jedis = jedisPool.getResource(); /// i am getting error from here**

@TrainingByCoding Your stacktrace doesn't comply your claim.

It seems these are the errors that have been being logged since version 3.6.0. You don't see these errors prior 3.6.0 only because these were not being logged by the older versions. If you want to avoid seeing these error logs, you may do so through your slf4j implementation/logging library.

Closed due to inactivity and possibly resolved/reduced.