Derby
  1. Derby
  2. DERBY-2420

XAConnection close method should throw an exception if it is called when the global transaction is associated with the connection.

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 10.2.2.0
    • Fix Version/s: None
    • Component/s: JDBC, Network Client
    • Urgency:
      Normal
    • Bug behavior facts:
      Embedded/Client difference

      Description

      As comments show in DERBY-2220 The Distributed Transaction Processing: The XA Specification forbids for a transaction manager or an application to call XAConnection.close method when there is a global transaction associated with the XA connection.

      Currently,

      Embedded driver throws the exception but the connection is left in a state when it cannot be used anymore and the locks held by the transaction can not be released later.

      Network driver allows the call of the method and closes the connection.

        Issue Links

          Activity

          Gavin made changes -
          Workflow jira [ 12399083 ] Default workflow, editable Closed status [ 12796891 ]
          Kathey Marsden made changes -
          Labels derby_triage10_5_2 derby_triage10_9
          Kathey Marsden made changes -
          Affects Version/s 10.2.2.0 [ 12312027 ]
          Kathey Marsden made changes -
          Labels derby_triage10_5_2
          Rick Hillegas made changes -
          Bug behavior facts [Embedded/Client difference]
          Component/s JDBC [ 11407 ]
          Hide
          Rick Hillegas added a comment -

          Triaged for 10.5.2: flagged as embedded/client difference.

          Show
          Rick Hillegas added a comment - Triaged for 10.5.2: flagged as embedded/client difference.
          Kathey Marsden made changes -
          Assignee Julius Stroffek [ julo ]
          Myrna van Lunteren made changes -
          Fix Version/s 10.3.0.0 [ 12310800 ]
          Hide
          Myrna van Lunteren added a comment -

          Unsetting fix version. If it still makes it into 10.3, appropriate fix version can be set when resolving.

          Show
          Myrna van Lunteren added a comment - Unsetting fix version. If it still makes it into 10.3, appropriate fix version can be set when resolving.
          Hide
          Julius Stroffek added a comment -

          There are two possible ways how the close method might behave when it should not be called:

          1.) throw an exception and leave the connection in the unchaged state.
          2.) close the connection, do cleanup and throw the exception.

          For now, embedded driver (EmbeddedConnection) throws the exception does not perform all the cleanup and leaves the connection in unusable state. The chain of function calls from EmbedPooledConnection.close -> EmbedConnection.close.

          People usually do not care much about the exceptions thrown by close method and expecting that there is not much they can do if it is not possible to close the connection. Therefore I think option 2 is a better choice. The exception about inproper usage would be thrown and even after that it would not be possible to use that connection anymore.

          Show
          Julius Stroffek added a comment - There are two possible ways how the close method might behave when it should not be called: 1.) throw an exception and leave the connection in the unchaged state. 2.) close the connection, do cleanup and throw the exception. For now, embedded driver (EmbeddedConnection) throws the exception does not perform all the cleanup and leaves the connection in unusable state. The chain of function calls from EmbedPooledConnection.close -> EmbedConnection.close. People usually do not care much about the exceptions thrown by close method and expecting that there is not much they can do if it is not possible to close the connection. Therefore I think option 2 is a better choice. The exception about inproper usage would be thrown and even after that it would not be possible to use that connection anymore.
          Julius Stroffek made changes -
          Fix Version/s 10.3.0.0 [ 12310800 ]
          Hide
          Julius Stroffek added a comment -

          I think this issue is worth while fixing before 10.3 release. I'll went through code and it should not be difficult to fix this. I'll create a patch at the beggining of the next week.

          Show
          Julius Stroffek added a comment - I think this issue is worth while fixing before 10.3 release. I'll went through code and it should not be difficult to fix this. I'll create a patch at the beggining of the next week.
          Hide
          Julius Stroffek added a comment -

          The field member 'inUnitOfWork_' in org.apache.derby.client.am.Connection is not maintained correctly for XA transactions.

          The following code does not throw any exception for client and embedded drivers (but it should throw):

          xaResource = xaConnection.getXAResource();
          xaResource.start(xid, XAResource.TMNOFLAGS);
          xaConnection.close();

          While if we execute some queries in unit of work and will try to close the connection afterwards, the close will fail even if the transaction would be disassociated from the connection (calling XAResource.end). It should be allowed to close the connection if there is no transaction associated.

          If the exception is thrown client driver throws exception:
          java.sql.SQLException: Cannot close a connection while a transaction is still active.
          while embedded driver throws
          java.sql.SQLException: Invalid transaction state.

          I would say that the exception thrown should be the same. I'll would prefer the first one since it explaines better what is going on.

          Show
          Julius Stroffek added a comment - The field member 'inUnitOfWork_' in org.apache.derby.client.am.Connection is not maintained correctly for XA transactions. The following code does not throw any exception for client and embedded drivers (but it should throw): xaResource = xaConnection.getXAResource(); xaResource.start(xid, XAResource.TMNOFLAGS); xaConnection.close(); While if we execute some queries in unit of work and will try to close the connection afterwards, the close will fail even if the transaction would be disassociated from the connection (calling XAResource.end). It should be allowed to close the connection if there is no transaction associated. If the exception is thrown client driver throws exception: java.sql.SQLException: Cannot close a connection while a transaction is still active. while embedded driver throws java.sql.SQLException: Invalid transaction state. I would say that the exception thrown should be the same. I'll would prefer the first one since it explaines better what is going on.
          Julius Stroffek made changes -
          Field Original Value New Value
          Link This issue relates to DERBY-246 [ DERBY-246 ]
          Julius Stroffek created issue -

            People

            • Assignee:
              Unassigned
              Reporter:
              Julius Stroffek
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:

                Development