Skip to content

Not able to catch Exception when validating #2712

@steinrr

Description

@steinrr

Expected behavior

Given the following exception in my logs:

2021-12-01 12:36:05,687 ERROR redis.clients.jedis.JedisFactory [http-nio-80-exec-9] Error while validating pooled Jedis object.
redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out
	at redis.clients.jedis.util.RedisInputStream.ensureFill(RedisInputStream.java:205)
	at redis.clients.jedis.util.RedisInputStream.readByte(RedisInputStream.java:43)
	at redis.clients.jedis.Protocol.process(Protocol.java:162)
	at redis.clients.jedis.Protocol.read(Protocol.java:227)
	at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:352)
	at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:270)
	at redis.clients.jedis.BinaryJedis.ping(BinaryJedis.java:380)
	at redis.clients.jedis.JedisFactory.validateObject(JedisFactory.java:214)
	at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:343)
	at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:223)
	at redis.clients.jedis.util.Pool.getResource(Pool.java:75)
	at redis.clients.jedis.JedisPool.getResource(JedisPool.java:370)
	at my.class.with.the.code.processApiCall(ApiController.java:155)
	at jdk.internal.reflect.GeneratedMethodAccessor30.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

I try to add a try-catch at line 155 (this is the getResource call), but the try catch "is never caught" - even if I do catch(Exception e). But it seems that my code still works fine and I am able to use the jedis - even if the validate failed.

How come? Is this because it is caught internally and reestablished somehow?

Actual behavior

See above

Steps to reproduce:

N/A

Redis / Jedis Configuration

Jedis version:

Redis version:

Java version:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions