Solr
  1. Solr
  2. SOLR-4920

DIH JdbcDataSource exception handling

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 4.3, 6.0
    • Fix Version/s: 4.4
    • Labels:
      None

      Description

      JdbcDataSource will incorrectly suppress exceptions when retrieving a connection from a JNDI context and fall back to trying to use DriverManager to obtain a connection. This makes it impossible to troubleshoot misconfigured JNDI DataSource.

      Additionally, when a SQLException is thrown while initializing a connection, such as in setAutoCommit(), the connection will not be closed. This can cause a resource leak.

      A patch will be attached with unit tests that addresses both issues.

      1. patch.diff
        10 kB
        Chris Eldredge

        Activity

        Hide
        Chris Eldredge added a comment -

        Patch against r1492257.

        Show
        Chris Eldredge added a comment - Patch against r1492257.
        Hide
        Commit Tag Bot added a comment -

        [trunk commit] shalin
        http://svn.apache.org/viewvc?view=revision&revision=1492537

        SOLR-4920: JdbcDataSource incorrectly suppresses exceptions when retrieving a connection from a JNDI context and falls back to trying to use DriverManager to obtain a connection. Additionally, if a SQLException is thrown while initializing a connection, such as in setAutoCommit(), the connection will not be closed.

        Show
        Commit Tag Bot added a comment - [trunk commit] shalin http://svn.apache.org/viewvc?view=revision&revision=1492537 SOLR-4920 : JdbcDataSource incorrectly suppresses exceptions when retrieving a connection from a JNDI context and falls back to trying to use DriverManager to obtain a connection. Additionally, if a SQLException is thrown while initializing a connection, such as in setAutoCommit(), the connection will not be closed.
        Hide
        Commit Tag Bot added a comment -

        [branch_4x commit] shalin
        http://svn.apache.org/viewvc?view=revision&revision=1492538

        SOLR-4920: JdbcDataSource incorrectly suppresses exceptions when retrieving a connection from a JNDI context and falls back to trying to use DriverManager to obtain a connection. Additionally, if a SQLException is thrown while initializing a connection, such as in setAutoCommit(), the connection will not be closed.

        Show
        Commit Tag Bot added a comment - [branch_4x commit] shalin http://svn.apache.org/viewvc?view=revision&revision=1492538 SOLR-4920 : JdbcDataSource incorrectly suppresses exceptions when retrieving a connection from a JNDI context and falls back to trying to use DriverManager to obtain a connection. Additionally, if a SQLException is thrown while initializing a connection, such as in setAutoCommit(), the connection will not be closed.
        Hide
        Shalin Shekhar Mangar added a comment -

        Fixed.

        Thanks Chris!

        Show
        Shalin Shekhar Mangar added a comment - Fixed. Thanks Chris!
        Hide
        Steve Rowe added a comment -

        Bulk close resolved 4.4 issues

        Show
        Steve Rowe added a comment - Bulk close resolved 4.4 issues
        Hide
        Mikhail Khludnev added a comment -

        I face usability issue with

        JdbcDataSource.java
        141 	try {
        142 	c = DriverManager.getConnection(url, initProps);
        143 	} catch (SQLException e) {
        144 	// DriverManager does not allow you to use a driver which is not loaded through
        145 	// the class loader of the class which is trying to make the connection.
        146 	// This is a workaround for cases where the user puts the driver jar in the
        147 	// solr.home/lib or solr.home/core/lib directories.
        148 	Driver d = (Driver) DocBuilder.loadClass(driver, context.getSolrCore()).newInstance();
        149 	c = d.connect(url, initProps);
        150 	}
        

        if I supply weird url, I've got SQLException, it's caught, then it calls c = d.connect(url, initProps); which returns null (which is pretty valid giving the javadoc). Then I have NPE where the connection is hit. There is no anything about SQLException reasons in the log. Isn't it worth to raise an issue?

        Show
        Mikhail Khludnev added a comment - I face usability issue with JdbcDataSource.java 141 try { 142 c = DriverManager.getConnection(url, initProps); 143 } catch (SQLException e) { 144 // DriverManager does not allow you to use a driver which is not loaded through 145 // the class loader of the class which is trying to make the connection. 146 // This is a workaround for cases where the user puts the driver jar in the 147 // solr.home/lib or solr.home/core/lib directories. 148 Driver d = (Driver) DocBuilder.loadClass(driver, context.getSolrCore()).newInstance(); 149 c = d.connect(url, initProps); 150 } if I supply weird url, I've got SQLException, it's caught, then it calls c = d.connect(url, initProps); which returns null (which is pretty valid giving the javadoc). Then I have NPE where the connection is hit. There is no anything about SQLException reasons in the log. Isn't it worth to raise an issue?

          People

          • Assignee:
            Shalin Shekhar Mangar
            Reporter:
            Chris Eldredge
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development