db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Julius Stroffek <Julius.Strof...@Sun.COM>
Subject What to do if the Connection.close is called when there is a transaction in progress
Date Tue, 26 Jun 2007 11:53:48 GMT
Hi All,

I would like to ask you about your opinion on behavior of
Connection.close method if it would be called when there is a
transaction in progress. I am working on a patch for DERBY-2420.

Currently derby is doing work in Connection.close and if it will find
out that closing the connection is not allowed it will throw the
exception. The connection will not be usable anymore (since some closing
code was ran) and is also not closed properly.

I consider two possibilities about the behavior:

The Connection.close method will throw the exception and will

1.) close the connection and will do all the required cleanup.
2.) NOT close the connection and will NOT do any cleanup.

I asked couple of guys (just users of JDBC interface) about their
opinion and they agreed that they would expect the option 1.) because
they do not care much about the exceptions being thrown in a close
method. They expect that there is not much they can do when
Connection.close method fails.

I wanted to implement the option 1.) but I experience some problems with
cleanup for XA transactions. The cleanup for XA transactions consists of
two steps - end the transaction association and rollback of that
transaction. That two steps should be ideally done atomically in a sense
that the thread doing the cleanup will obtain the required locks and
will do both steps afterward. If the connection socket is closed the
correct cleanup will take place on a server. However client sometimes
may call Connection.closeForReuse which does not close the socket but it
will just send close statement request for every opened statement. In
case of a network driver it is not possible to end the transaction
association and rolling back the global transaction atomically. This may
sometimes lead to strange exceptions being thrown to the user (if two
cleanup codes would run simultaneously) but does not affect the

I can see these options how to deal with this

1.) do not close the connection if closing the connection is not allowed
and leave the connection in open state.

2.) do not do the XA transaction cleanup if Connection is going to be
closed for re-use. XA transaction timeout feature might be used to
address the cleanup.

3.) close the connection and socket also in Connection.closeForReuse if
the XA transaction cleanup is necessary. Do not recycle the connection.
The correct cleanup will take place on a server side.

Thanks for your opinions


View raw message