{"record":{"id":"953ea410fc24a65f","repo":"redis/jedis","slug":"error-while-force-disconnecting-connection","errorCode":null,"errorMessage":"Error while force disconnecting connection: ","messagePattern":"Error while force disconnecting connection: ","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/main/java/redis/clients/jedis/mcf/TrackingConnectionPool.java","lineNumber":77,"sourceCode":"\n    @Override\n    protected void initialize(Connection conn) {\n      // Track the connection while it is being initialized so forceDisconnect() can interrupt\n      // a thread that is blocked inside HELLO/AUTH/CLIENT round-trips.\n      factoryTrackedObjects.add(conn);\n      try {\n        super.initialize(conn);\n      } finally {\n        factoryTrackedObjects.remove(conn);\n      }\n    }\n\n    public void forceDisconnect() {\n      for (Connection connection : factoryTrackedObjects) {\n        try {\n          connection.forceDisconnect();\n        } catch (Exception e) {\n          log.warn(\"Error while force disconnecting connection: \" + connection.toIdentityString(),\n            e);\n        }\n      }\n    }\n\n  }\n\n  public static class Builder {\n    private HostAndPort hostAndPort;\n    private JedisClientConfig clientConfig;\n    private GenericObjectPoolConfig<Connection> poolConfig;\n    private Cache cache;\n    private MaintenanceNotificationsConfig maintenanceNotificationsConfig;\n\n    public Builder hostAndPort(HostAndPort hostAndPort) {\n      this.hostAndPort = hostAndPort;\n      return this;\n    }","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/mcf/TrackingConnectionPool.java#L59-L95","documentation":"This is a warning logged by TrackingConnectionPool.forceDisconnect() when calling connection.forceDisconnect() on one of its tracked connections throws an exception. The pool catches the exception per-connection so that one bad socket does not prevent the remaining connections from being force-disconnected; it logs the connection identity and the underlying cause, then continues the loop. It typically surfaces during client close/failover shutdown when the underlying socket is already dead.","triggerScenarios":"Calling forceDisconnect() (e.g. during client close or a failover-driven shutdown) on a connection whose underlying socket close/disconnect throws — e.g. socket already closed, broken pipe on the socket channel, or an IOException raised by the connection implementation during forced teardown.","commonSituations":"Shutting down a RedisClient/UnifiedJedis after the Redis server was killed or the network dropped; concurrent close from multiple threads where one thread already closed the connection; failover handlers in the mcf (multi-db) module tearing down connections to a dead endpoint.","solutions":["Inspect the logged cause ('e') — if it is a socket closed/broken pipe error, the connection was already dead and the warning is benign; no action needed.","Avoid closing the client (or calling forceDisconnect) concurrently from multiple threads; ensure a single shutdown path.","Upgrade Jedis — connection teardown error handling has been hardened across releases.","If it happens repeatedly during failover, verify the endpoint health and network stability before the shutdown/failover is triggered."],"exampleFix":"// before\npool.forceDisconnect(); // warnings if sockets already dead, unclear cause\n// after\ntry {\n  pool.forceDisconnect();\n} catch (Exception e) {\n  log.warn(\"forceDisconnect failed during shutdown\", e); // check logged per-connection cause\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  client.close(); // internally force-disconnects tracked connections\n} catch (Exception e) {\n  log.warn(\"Client shutdown reported force-disconnect issues; per-connection causes were logged by the pool\", e);\n} // per-connection 'Error while force disconnecting' warnings for already-dead sockets are benign and need no retry","preventionTips":["Close the client from a single thread/shutdown hook; never call close() and failover handlers concurrently.","Expect these warnings after killing Redis or dropping the network — treat them as informational when the cause is a closed socket.","Check the logged underlying cause before reacting; only investigate if the exception is unexpected (not socket-closed/broken-pipe)."],"tags":["connection-pool","socket-close","shutdown","failover","log-warning"],"backgroundTag":"connection-close-failed","analyzedSha":"6dac31d4c224fb3257c216f3985340c6f500cdcb","analyzedAt":"2026-09-08T04:55:01.204Z","contentChangedAt":"2026-09-08T04:55:01.204Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}