You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Eickvonder Bjoern <Ei...@inside-online.de> on 2007/12/11 14:15:46 UTC

[DBCP] Datasource getConnection returns an already closed connection

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?


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?


Kennen Sie schon die inside Schulungsma?nahme zur VVG-Reform? Erfahren Sie mehr dazu unter www.vvg-konzept.de. 

Besuchen Sie uns an unserem Stand C 8 auf der Learntec in Karlsruhe vom 29.-31.01.08.


Diese Mitteilung ist vertraulich und ausschlie?lich an den entsprechenden Empfanger gerichtet. Wenn Sie diese Mitteilung versehentlich erhalten haben, durfen Sie diese nicht kopieren, weitergeben oder in sonstiger Weise verbreiten. Bitte informieren Sie in einem solchen Fall den Absender und loschen Sie die Mitteilung sowie alle zugehorigen Anhange.


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


Re: [DBCP] Datasource getConnection returns an already closed connection

Posted by Mark Shifman <ma...@yale.edu>.
Look at the bottom of this howto.  the is a discussion of Random 
Connection Closed Exceptions and a remedy.
http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html
mas
Eickvonder Bjoern 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?
>
>
> 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?
>
>
> Kennen Sie schon die inside Schulungsma?nahme zur VVG-Reform? Erfahren Sie mehr dazu unter www.vvg-konzept.de. 
>
> Besuchen Sie uns an unserem Stand C 8 auf der Learntec in Karlsruhe vom 29.-31.01.08.
>
>
> Diese Mitteilung ist vertraulich und ausschlie?lich an den entsprechenden Empfanger gerichtet. Wenn Sie diese Mitteilung versehentlich erhalten haben, durfen Sie diese nicht kopieren, weitergeben oder in sonstiger Weise verbreiten. Bitte informieren Sie in einem solchen Fall den Absender und loschen Sie die Mitteilung sowie alle zugehorigen Anhange.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>   


-- 
 Mark Shifman MD. Ph.D.
 Yale Center for Medical Informatics
 Phone (203)737-5219
 mark.shifman@yale.edu


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


Re: [DBCP] Datasource getConnection returns an already closed connection

Posted by Phil Steitz <ph...@gmail.com>.
On Dec 11, 2007 6:15 AM, Eickvonder Bjoern
<Ei...@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