Connection.isConnected() falsly returns true after network disconnect/reconnect
See original GitHub issueWhen I connect to the Redis instance with Jedis and then disable ethernet adapter in windows and reanable it, isConnected() method will return true, when in reality it is not and all redis commands like ping, lpush, etc. will throw java.net.SocketException.
Caused by: java.net.SocketException: Connection reset by peer: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109)
at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
at redis.clients.util.RedisOutputStream.flushBuffer(RedisOutputStream.java:31)
at redis.clients.util.RedisOutputStream.flush(RedisOutputStream.java:223)
at redis.clients.jedis.Connection.flush(Connection.java:276)
... 11 more
Issue Analytics
- State:
- Created 9 years ago
- Comments:7
Top Results From Across the Web
Connection.isConnected() falsly returns true after network ...
When I connect to the Redis instance with Jedis and then disable ethernet adapter in windows and reanable it, isConnected() method will ...
Read more >[SOLVED] Reconnect ESP8266 NodeMCU to Wi-Fi Network ...
This example shows how to connect to a network and checks every 30 seconds if it is still connected. If it isn't, it...
Read more >If isConnected returns true, why does Exeption say that it isn't ...
isConnected() tells you about the state of the Socket . If you have ever connected or accepted it, it returns true. Even after...
Read more >Troubleshoot network problems - Azure Sphere | Microsoft Learn
For network failures, a high-level application can call WifiConfig_GetNetworkDiagnostics to gather information about the problem.
Read more >Managing network connection status in React Native
The netInfo library fires the isConnected=false. The application is unable to use internet after. Even though other application on my device are ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Welcome to the joys of network programming: The only way to find out if you can send data over a socket, is sending data over a socket. This is true for any networking library, not just Jedis.
isConnected() == false
tells you that the client needs to reconnect (which it does automatically).isConnected() == true
does not tell you anything. The next command might get through, or it might not. Even if the TCP stream is perfectly fine and healthy at the time you callisConnected()
orping()
, network might go down the millisecond after. You ALWAYS have to expect commands to fail. CheckingisConnected()
beforehand is useless.That said,
isConnected()
will only lie to you if the socket is in an undefined state (disconnected, but the operating system does not know that yet). It returns true if the socket appear to be connected. That’s fair, I think.It still doesn’t make a lot of sense because it is not really connected. Normally an isConnected() function checks that a connection is still alive, not that the object is initialized or resources are present. The name is misleading since the function returns true when the connection is dead and redis is down. I think maybe something like isInitialized() would make more sense. Just my two cents.