Why jedis Connection marks with broken on exception

Skip to first unread message


Nov 28, 2021, 8:58:34 AM11/28/21
to Jedis
Hi experts,

From the redis.clients.jedis.Connection.java, found the code snippets below:

public void sendCommand(final ProtocolCommand cmd, final byte[]... args) {
try {
Protocol.sendCommand(outputStream, cmd, args);
} catch (JedisConnectionException ex) {
* When client send request which formed by invalid protocol, Redis send back error message
* before close connection. We try to read it to provide reason of failure.
try {
String errorMessage = Protocol.readErrorLineIfPossible(inputStream);
if (errorMessage != null && errorMessage.length() > 0) {
ex = new JedisConnectionException(errorMessage, ex.getCause());
} catch (Exception e) {
* Catch any IOException or JedisConnectionException occurred from InputStream#read and just
* ignore. This approach is safe because reading error message is optional and connection
* will eventually be closed.
// Any other exceptions related to connection?
broken = true;
throw ex;

On exception, the connection will be marked with broken = true. In this case, isn't the connection will be closed during the period check? And on the subsequence successful calls, why we don't reset back the broken flag to false;


Sazzadul Hoque

Nov 28, 2021, 9:26:44 AM11/28/21
to jedis...@googlegroups.com
The focus of the 'broken' variable is always to support different implementations 'Pool<Jedis>'. In a pooled scenario, there is no expected subsequent call if 'broken = true'. 

In a non-pooled scenario, there is no other way but to use the same connection irrespective of the value of 'broken'.

So in neither case resetting the flag had any effect.

You received this message because you are subscribed to the Google Groups "Jedis" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jedis_redis...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jedis_redis/aec7a970-fb58-4ff6-8586-69263cb68670n%40googlegroups.com.
Reply all
Reply to author
0 new messages