#112 Long timeout when connecting to non-existent DB

closed-invalid
nobody
None
7
2012-11-10
2012-11-10
No

At least with MySQL, if you try to connect to a non-existent database, it will take quite a while (30 seconds or so) to fail. This is of course totally unexpected, since if you try to do the same thing using DriverManager, it fails immediately.

ComboPooledDataSource ds = new ComboPooledDataSource();
ds.setDriverClass("com.mysql.jdbc.Driver");
ds.setJdbcUrl("jdbc:mysql://localhost:3306/DOES_NOT_EXIST");
ds.setUser("jdoe");
ds.setPassword("secret");
ds.setMinPoolSize(1);
ds.setMaxPoolSize(10);
try {
ds.getConnection(); // This will hang for 30 seconds or so
} catch(SQLException ex) {
// You will eventually get an exception here
}

This is a complete show-stopper for us, so we're going to have to use DBCP for now. Thanks!

Discussion

    • priority: 5 --> 7
     
  • Steve Waldman
    Steve Waldman
    2012-11-10

    • status: open --> closed-invalid
     
  • Steve Waldman
    Steve Waldman
    2012-11-10

    Hi,

    By default c3p0 retries unsuccessful Connection acquisitions 30 times with a delay of 1 second between attempts. This is tunable. If you want c3p0 to fail immediately upon an Exception in Connection acquisition (what you see in DriverManager), simply set the config parameter

    c3p0.acquireRetryAttempts=1

    (When this setting is one, the term "retry" is a bit of a misnomer. Really acquireRetryAttempts sets the total number of attempts to fetch a Connection from the database that will be made before c3p0 declares a failure and throws an Exception to clients wait()ing for new Connection.)

    See http://www.mchange.com/projects/c3p0/#configuring_recovery

     
  • Aha! Thanks for the pointer. I must admit it wasn't entirely obvious from the docs.