I am able to fix the problem by modifying my create function in the
ConnectionPool concrete class. I have modified the create function to set
the ReconnectOption for connection as true. By setting the ReconnectOption
the queries works fine even if the MySQL server is restarted in the
There are two designs which I can think of eliminating the bad connection
from the pool:
Check for bad connection in the grab function and remove them using remove
Client code is simple. They do not have to do extra work. Library does all
the heavy lifting.
Check is done every time. But I do not know what check we need to do and how
expensive it can be.
As suggested by you in your earlier mail.If an mysqlpp Exception occur,
check if it because of a bad connection. Remove such connections from the
pool using exchange method. Function exchange is a syntactic sugar for
remove and grab.
Might be efficient than design1 as we do not need to check every time when a
connection is returned from the pool.
Client code has to do more work.
For the sake of maintainability and easier client code I prefer Design1. But
now to implement Design1 I have following questions:
1. Do we need to really implement the code to remove the bad connection from
the pool. What are the scenarios? Does the reconnect option solves all the
2. Is there a way to find out the bad connection without executing a query
on it. Something like ping ?
I will be happy to add a exchange method if you see other scenarios where we
can end up with a bad connection in the pool.