Hello,

sorry to bother you, but I have not received any answer
to my previous post.  I am quite sure that I have found
a bug and a fix for it in dbcp.  Could someone please
take a little time just to verify?

Even if you cannot reproduce the problem, I think you
will be convinced by looking at the code, see my proposed
change below.

Thank you,
Olli

P.S. sorry for the weird line breaks ... Outlook ...

> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, August 07, 2007 10:33 AM
> To: [email protected]
> Subject: dbcp: InstanceKeyDataSourcegetConnection, exception during
> setup Defaults()
> 
> 
> Hello,
> 
> my webapp uses Sybase jConnect2 5.5, commons-dbcp 1.2.1,
> spring framework 2.0.1.
>  
> My webapp runs fine, but after a few days the following
> occurs in InstanceKeyDataSource.getConnection:
> com.sybase.jdbc2.jdbc.SybConnectionDeadException: JZ0C0 
> (stacktrace see
> below).
> Probably this is because of sybase timeouts and acceptable behaviour.
> 
> However, I have the impression that the connection is not 
> properly released.
> 
> When this has happend a few times, the pool seems to get 
> exhausted: I get 
> "org.apache.commons.dbcp.SQLNestedException: Could not 
> retrieve connection
> info from pool",
> see stacktrace below.
> 
> After a restart, everthing is fine.
> 
> I have analyzed the problem and I think there is a bug in the 
> last lines of 
> org.apache.commons.dbcp.datasources.
> InstanceKeyDataSource.getConnection(String username, String password)
> 
> It says:
> 
> -------
> Connection con = info.getPooledConnection().getConnection();        
> setupDefaults(con, username);
> con.clearWarnings();
> return con;
> -------
> 
> I my case, the exception happens in the second line of this snippet,
> so no code gets the chance close con and release the resources.
> 
> I propose to change it to:
> 
> -------
> Connection con = info.getPooledConnection().getConnection();    
> try
> {
>   setupDefaults(con, username);
>   con.clearWarnings();
>   return con;
> }
> catch (Exception exc)
> {
>   try
>   {
>     con.close();
>   }
>   catch (Exception exc)
>   {
>     getLogWriter().println(
>      "ignoring exception during close: " + exc);  // uncertain here.
>   }
>   throw exc;
> }
> -------               
> 
> What do you think?
> 
> Best regards and thank you for your effort,
> 
> Olli
> 
> 
> 
> The two exceptions follow.
> 
> -----------------------------
> 
> java.sql.SQLException: JZ006: Caught IOException:
> com.sybase.jdbc2.jdbc.SybConnectionDeadException: JZ0C0: Connection is
> already closed.
>       at
> com.sybase.jdbc2.jdbc.ErrorMessage.raiseErrorCheckDead(ErrorMe
> ssage.java:709
> )
>       at com.sybase.jdbc2.tds.Tds.handleIOE(Tds.java:3071)
>       at com.sybase.jdbc2.tds.Tds.cancel(Tds.java:1412)
>       at com.sybase.jdbc2.tds.Tds.cancel(Tds.java:1341)
>       at
> com.sybase.jdbc2.jdbc.SybStatement.doCancel(SybStatement.java:564)
>       at
> com.sybase.jdbc2.jdbc.SybStatement.updateLoop(SybStatement.java:1645)
>       at
> com.sybase.jdbc2.jdbc.SybStatement.executeUpdate(SybStatement.
> java:1598)
>       at
> com.sybase.jdbc2.jdbc.SybPreparedStatement.executeUpdate(SybPr
> eparedStatemen
> t.java:89)
>       at com.sybase.jdbc2.tds.Tds.setOption(Tds.java:1111)
>       at
> com.sybase.jdbc2.jdbc.SybConnection.setAutoCommit(SybConnectio
> n.java:634)
>       at
> org.apache.commons.dbcp.cpdsadapter.ConnectionImpl.setAutoComm
> it(ConnectionI
> mpl.java:325)
>       at
> org.apache.commons.dbcp.datasources.SharedPoolDataSource.setup
> Defaults(Share
> dPoolDataSource.java:212)
>       at
> org.apache.commons.dbcp.datasources.InstanceKeyDataSource.getC
> onnection(Inst
> anceKeyDataSource.java:654)
>       at
> org.apache.commons.dbcp.datasources.InstanceKeyDataSource.getC
> onnection(Inst
> anceKeyDataSource.java:615)
>       at
> org.springframework.jdbc.datasource.DataSourceUtils.doGetConne
> ction(DataSour
> ceUtils.java:112)
>       at
> org.springframework.jdbc.datasource.DataSourceUtils.getConnect
> ion(DataSource
> Utils.java:77)
>       at
> org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplat
> e.java:513)
>       at
> org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.
> java:581)
>       at
> org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.
> java:610)
>       at
> org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.
> java:614)
>       at
> org.springframework.jdbc.core.JdbcTemplate.queryForObject(Jdbc
> Template.java:
> 656)
>       at
> org.springframework.jdbc.core.JdbcTemplate.queryForObject(Jdbc
> Template.java:
> 668)
>       at
> org.springframework.jdbc.core.JdbcTemplate.queryForInt(JdbcTem
> plate.java:694
> )
> --------------------------------
> 
> Servlet.service() for servlet jobaccess threw exception :
> org.apache.commons.dbcp.SQLNestedException: Could not 
> retrieve connection
> info from pool
>       at
> org.apache.commons.dbcp.datasources.SharedPoolDataSource.getPo
> oledConnection
> AndInfo(SharedPoolDataSource.java:169)
>       at
> org.apache.commons.dbcp.datasources.InstanceKeyDataSource.getC
> onnection(Inst
> anceKeyDataSource.java:631)
>       at
> org.apache.commons.dbcp.datasources.InstanceKeyDataSource.getC
> onnection(Inst
> anceKeyDataSource.java:615)
>       at
> org.springframework.jdbc.datasource.DataSourceUtils.doGetConne
> ction(DataSour
> ceUtils.java:112)
>       at
> org.springframework.jdbc.datasource.DataSourceUtils.getConnect
> ion(DataSource
> Utils.java:77)
>       at
> org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplat
> e.java:513)
>       at
> org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.
> java:581)
>       at
> org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.
> java:610)
>       at
> org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.
> java:614)
> 
> -- 
>   Oliver Matz
>   Development
>   ppi Media GmbH
>   Deliusstrasse 10
>   24114 Kiel, Germany
>   Geschäftsführer: Norbert Ohl, Martin Ruhle
>   Amtsgericht Hamburg, HRB 84308
>   phone  +49 (0) 431-53 53 -422
>   fax    +49 (0) 431-53 53 -222
>   www.ppimedia.de
> 
>   Explore your printnet!
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to