You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Ol...@ppimedia.de on 2007/08/14 08:58:35 UTC

repost: dbcp: InstanceKeyDataSourcegetConnection, exception duri ng setup Defaults()

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: Oliver.Matz@ppimedia.de [mailto:Oliver.Matz@ppimedia.de]
> Sent: Tuesday, August 07, 2007 10:33 AM
> To: user@commons.apache.org
> 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: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 

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


Re: repost: dbcp: InstanceKeyDataSourcegetConnection, exception duri ng setup Defaults()

Posted by Phil Steitz <ph...@gmail.com>.
Oliver,

Thanks for reporting this and sorry for the delayed response.  It
would be best to open a JIRA ticket for this issue so we do not lose
track of it.  If you don't mind doing that, you can enter issues
against commons dbcp by following the "bug report" link on this page:
http://commons.apache.org/dbcp/issue-tracking.html

You can submit a patch with the bug report, using the "attach file"
link on the issue entry page. The instructions for making patches are
here:
http://commons.apache.org/patches.html

Thanks again for the feedback.  This looks like a bug to me and your
suggested change looks reasonable.  As a workaround, if you have not
already done so, you could try setting the testOnBorrow property to
true.  That should cause the exception to be thrown earlier and the
bad connection to be removed from the pool.

Phil

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