I configured my Spring Boot application to use BoneCP with PostgreSQL's failover mechanism (jdbc:postgresql://host1:port,host2:port,host3:port/my_db?currentschema=public
) by providing several hosts that contain the same replicated database.
When doing tests, I have observed that if the connection is dropped, the application will return a PSQLException: An I/O error occurred while sending to the backend
followed by several PersistenceException
to the web browser (E.g when requesting stored data) and won't try to switch to the next available host unless the user manually reloads the page triggering a reconnection.
I would like to catch these exceptions and force a reconnection (Or up to X reconnections, with Y ms between each, if possible) before anything is returned to the user. Naturally, if all hosts are unreachable (Or a different issue appears) an exception would be thrown as usual