commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Phil Steitz" <phil.ste...@gmail.com>
Subject Re: [DBCP] Datasource getConnection returns an already closed connection
Date Wed, 12 Dec 2007 03:40:59 GMT
On Dec 11, 2007 6:15 AM, Eickvonder Bjoern
<Eickvonder.Bjoern@inside-online.de> wrote:
> Hi,
>
> I've a problem with Tomcat 5.5.25 which uses DBCP 1.2.2 in the following
> scenario:
>
> 1.) I've declared pooling in the context-file as follows:
>
>   <Resource name="jdbc/test" auth="Container"
> type="javax.sql.DataSource"
>     username="root"
>     password="root"
>     driverClassName="com.mysql.jdbc.Driver"
>     url="jdbc:mysql://localhost/test"
>     maxActive="2"
>     maxIdle="1"
>     minIdle="1"
>     maxWait="60000"
>     timeBetweenEvictionRunsMillis="300000"
>     minEvictableIdleTimeMillis="1800000"
>         />
>
> 2.) Now I retrieve a connection twice via Datasource getConnection -
> everything works fine.
> 3.) Now the database closes the idle connection by either timeout or
> server restart.
> 4.) If I now try to retrieve a connection again I retrieve a closed
> connection, leading to further exceptions.
>
> In Tomcat 5.5.23 using DBCP 1.2.1 step 4 returned a valid connection.
>
> Is this a bug or feature of DBCP 1.2.2?

Should be a feature of both versions, IIUC what is going on.  Since
you have not supplied a validation query or set testOnBorrow,
testOnReturn to true, connections are not validated before being
returned to the pool or when borrowed via getConnection.  See the
tomcat or dbcp docs for how to set these options.  The different
behavior may be due to the change from pool 1.2 in DBCP 1.2.1 to 1.3
in DBCP 1.2.2.  Pool 1.3 cycles through connections in FIFO order
(least recently used connections returned first), while 1.2 works in
LIFO order.  Should be no difference with maxIdle = 1, though.  In any
case, setting up validation will guard against bad connections
returned from the pool.
>
>
> Some background info:
> The getConnection call in my application is done by JPOX 1.1.7 and and
> adding some debug code into its source showed that at line 898 in
>
> http://jpox.cvs.sourceforge.net/jpox/JPOX/Core/src/java/org/jpox/store/r
> dbms/adapter/DatabaseAdapter.java?hideattic=0&revision=1.111.2.2&view=ma
> rkup
>
> the connection is valid/open for DBCP 1.2.1 and closed for DBCP 1.2.2
> concerning step 4.
>
>
> Bjoern Eickvonder
>
>
> PS:
> Moreover I found out that calling close() on an already
> closed-Connection (as in line 933 of the JPOX DatabaseAdapter) leads to
> an SQLException using DBCP while the Java Api for java.sql.Connection
> states that
> "Calling the method close on a Connection object that is already closed
> is a no-op."! Bug?

Yes, while this was by design in DBCP 1.1, 1.2.x, we have agreed it is
a bug (http://issues.apache.org/jira/browse/DBCP-233) and it has been
addressed in the current development branch and will be fixed in DBCP
1.3.

Phil

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message