title: Is MariaDB JDBC driver ignoring connection timeout?
body: <p>In the application we are working on, the user can connect to external RDBMSs by entering an arbitrary JDBC connection URL into a text field. One of our customers reported that our application server freezes (indefinitly) at 0% CPU when he accidentally tried to connect to a Microsoft SQL Server with a MySQL JDBC URL. </p>
  
  <p>The following Java snippet illustrates the situation:</p>
  
  <pre><code>public static void main(String[] args){
  
      // note: the application running on localhost:1433 is ACTUALLY
      // an MS SQL Server instance!
      String jdbcUrl = "jdbc:mysql://localhost:1433/my-db";
  
      // enable JDBC Driver Manager logging
      DriverManager.setLogWriter(new PrintWriter(System.err));
  
      // set a timeout of 5 seconds for connecting (which is blissfully ignored!)
      DriverManager.setLoginTimeout(5);
  
      // open the connection (which should fail, but freezes instead)
      try (Connection c =  DriverManager.getConnection(jdbcUrl)){
          System.out.println("This should never be reached due to wrong JDBC URL.");
      }catch(Exception e){
          System.out.println("This is expected (but never printed).");
      }
      System.out.println("This is never printed either.");
  }
  </code></pre>
  
  <p><strong>To run the snippet:</strong></p>
  
  <ul>
  <li>have a SQL Server instance running on localhost:1433 (content does not matter) </li>
  <li>have the MariaDB JDBC driver version 2.2.5. (latest) on your classpath.</li>
  </ul>
  
  <p><strong>Questions:</strong></p>
  
  <ul>
  <li>1) Could this be a bug in the MariaDB JDBC driver? A google search revealed nothing in this regard.</li>
  <li>2) How should I work around this issue? I don't want my server to freeze when the user accidentally inserts an invalid JDBC URL.</li>
  </ul>
  
  <p>I tried several other JDBC drivers (MySQL, DB2, Oracle...) and they all handle this issue gracefully, only the MariaDB JDBC driver freezes the JVM.</p>