Skip to content

Commit 611324e

Browse files
committed
[core] throw an error when unable to get a connection
When a wrong URL is provided, it can happen that newConnection() returns null. If this happens during configure_connection, the whole process is called over and over again and results in a stack overflow. Instead, just throw an error. Noticed because a new test in Rails master tries to connect with "mysql2:///wait_timeout=60", an URL unknown to JDBC.
1 parent d68329f commit 611324e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/java/arjdbc/jdbc/RubyJdbcConnection.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,10 @@ public synchronized IRubyObject reconnect(final ThreadContext context) {
727727

728728
private void connectImpl(final boolean forceConnection) throws SQLException {
729729
setConnection( forceConnection ? newConnection() : null );
730-
if ( forceConnection ) configureConnection();
730+
if (forceConnection) {
731+
if (getConnectionImpl() == null) throw new SQLException("Didn't get a connection. Wrong URL?");
732+
configureConnection();
733+
}
731734
}
732735

733736
@JRubyMethod(name = "read_only?")

0 commit comments

Comments
 (0)