Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7164050

Crash when two thread working on a JdbcOdbc connection.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P5
    • Resolution: Won't Fix
    • Affects Version/s: 8
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:

      Description

      Licensee is making a fix contribution for the JDBC/ODBC bridge.

      Details from Licensee:

      --------
      THE PROBLEM
      The change resolves a crash issue seen in a customer environment where two threads working with a JdbcOdbc connection.

      Thread T1 is trying to close a connection by invoking JdbcOdbcConnection.close() which in turn calls JdbcOdbcDriver.closeConnection(). The logic in closeConnection() finds that the connection is being closed and consequently frees the environment handle, and the local variable hEnv representing the environment handle is set to 0.

      A second thread T2 is trying to open a new connection via java.sql.DriverManager.getConnection() which in turn calls JdbcOdbcDriver.connect(). Control eventually enters JdbcOdbcDriver.initialize(), where a the validity of hEnv is checked and a new connection is created.

      There is a window in which T2 sees the hEnv as valid and goes ahead with connection allocation while T1 frees it up. The result in this scenario is a crash.

      THE FIX
      1. Make the access to hEnv synchronized. hEnv is accessed via methods connect(), initialize(), getConnectionAttributes(), closeConnection() so these methods are now declared with the synchronized keyword.
      2. I found that a dedicated connection handle (hDbc) is maintained for getPropertyInfo(). After the hEnv is cleared this handle also needs to be cleared. hDbc is now cleared before the environment handle is freed.
      3. A bit of refactoring to move the repetitive code for closing the hDbc to a private method.

      See Comments for suggested fix.

        Attachments

          Activity

            People

            Assignee:
            lancea Lance Andersen
            Reporter:
            dkorbel David Korbel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: