commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hontvari Jozsef (JIRA)" <>
Subject [jira] Commented: (DBCP-329) SQLException: Already closed.
Date Tue, 30 Mar 2010 13:02:27 GMT


Hontvari Jozsef commented on DBCP-329:

>If the driver returns false, something bad has happened, because DBCP thinks the connection
is open and the driver is reporting that it is closed.

As I see two kind of bad thing could have happened:
1) There was an exception in a previous operation on the connection. DBCP know about this
fact, as DBCP is part of the call chain. The client code also knows about that exception,
moreover, that exception contains relevant information about the problem. There is no need
to issue a secondary exception on close() which does not add information (or actually mislead).
2) The client code closed the underlying connection. 
That may indicate a bug, but you have to work hard to make this bug, you need to access the
underlying connection and then close it. It is also possible that is is not a bug: the client
code itself closes the underlying connection after using it because for example some problem
happened. In this case it is a feature if DBCP does check isClosed and acknowledges it by
not throwing an exception.
3) (A third possibility could be that the client borrowed the connection and does not use
it. But in this case the client is not interested in the state of the is connection at all)

Here is the template code which should be used if the current behavior remains:
Connection connection = ...
try {
} finally {
  try {
  } catch (SQLException e) {
    logger.warn("Close was not successful. This is likely caused by another exception, look
at later log entries.", e);

> SQLException: Already closed.
> -----------------------------
>                 Key: DBCP-329
>                 URL:
>             Project: Commons Dbcp
>          Issue Type: Bug
>    Affects Versions: 1.4
>         Environment: MySQL
>            Reporter: Hontvari Jozsef
> After upgrading to 1.4 I see such exceptions logged:
> java.sql.SQLException: Already closed.
> 	at org.apache.commons.dbcp.PoolableConnection.close(
> 	at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.close(
> 	...
> This should never happen. According to the Connection.close() javadoc: 
> "Calling the method close on a Connection object that is already closed is a no-op."
> Moreover, I am pretty sure that our code does not close the connection twice. But because
the close() is called in a finally block, it is possible that this exception hides another
exception. Unfortunately I cannot reproduce it, even though it occurs regularly.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message