Broken connections never unbreak

Skip to first unread message

Kirk Bulis

Nov 28, 2021, 8:58:34 AM11/28/21
to Jedis
As I look at how the Connection is managed, it seems the connection instance starts life with broken = false, but nowhere in the code does broken get set back to false, say on disconnect().

Why this matters: When trying to connect to a server that currently not reachable, the following code should work:

private val redis: Jedis,
if (!redis.isConnected || redis.isBroken) {
  try {
  catch (eX: Exception) {


which will always be true if the connection was ever broken because there is no code anywhere to set broken = false. I think this is a one line fix to simply set broken = false during disconnect() or right before

socket = socketFactory.createSocket();
during connect().

Should I bug it up? and then PR? Am I missing the right way to reset a connection?

Any help much appreciated. Thanks!

Sazzadul Hoque

Nov 28, 2021, 9:32:41 AM11/28/21
It is expected that the connection would be re-created, not re-connected, when it is broken.

Yeah, there are places for improving docs.

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
To view this discussion on the web visit

Kirk Bulis

Nov 28, 2021, 8:33:46 PM11/28/21
to Jedis
Thanks for replying. Yeah, I suppose creating a new Jedis instance is one way to solve, but I think it also works to reset the "broken" flag when creating a new socket. This seems intuitive and should work:

(server is down)
(fails, broken = true)
(sever is now up)

but it won't because of the stickiness of broken = true in the code. So, it seems good to me that the only thing that could be broken is the socket, and we're allocating a new one on connect(), so putting broken = false here:

seems safe.
Reply all
Reply to author
0 new messages