Bug 29867 - jdbc database Connecting pool leak
Summary: jdbc database Connecting pool leak
Status: RESOLVED WONTFIX
Alias: None
Product: Tomcat 5
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 5.0.19
Hardware: PC Linux
: P3 critical (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-06-30 10:40 UTC by haibin zhang
Modified: 2004-11-16 19:05 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description haibin zhang 2004-06-30 10:40:32 UTC
When I put jdbc connecting  in  DefaultContext, and When I put my WAR file in
webapps dir ,tomcat will auto deploy it, but tomcat can't release connecting
pool before it undeploy the old WAR. the connecting size will increase more and
more ,don't reduce. 
You can test it, use netstat |wc -l to see how many connecting to database. then
for a long time , system file description will be used over, then system has no
resource to use.

How can I release the connecting pool by manual in my program?

attachment is the server.xml that I use.

<Server port="8005" shutdown="SHUTDOWN">
  <GlobalNamingResources>
    <!-- Used by Manager webapp -->
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
      description="User database that can be updated and saved">
    </Resource>
    <ResourceParams name="UserDatabase">
      <parameter>
        <name>factory</name>
        <value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
      </parameter>
      <parameter>
        <name>pathname</name>
        <value>conf/tomcat-users.xml</value>
      </parameter>
    </ResourceParams>
  </GlobalNamingResources>

  <Service name="Catalina">
    <Connector port="80" />

    <!-- This is here for compatibility only, not required -->
    <Connector port="8009" protocol="AJP/1.3" />

    <Engine name="Catalina" defaultHost="localhost">
      <Logger className="org.apache.catalina.logger.FileLogger" />

      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
             resourceName="UserDatabase" />

        <Realm  className="org.apache.catalina.realm.JDBCRealm" debug="0"
             driverName="oracle.jdbc.driver.OracleDriver"
          connectionURL="jdbc:oracle:thin:@localhost:1521:nms"
         connectionName="test" connectionPassword="test"
              userTable="view_users" userNameCol="username" userCredCol="password"
          userRoleTable="tb_user_roles" roleNameCol="rolename" />

        <DefaultContext>

        <Resource name="jdbc/AdminDB" auth="Container" type="javax.sql.DataSource"/>

        <ResourceParams name="jdbc/AdminDB">
<parameter>
                <name>factory</name>
                <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
            </parameter>
            <parameter>
            <name>driverClassName</name>
                <value>oracle.jdbc.driver.OracleDriver</value>
            </parameter>
            <parameter>
                <name>url</name>
                <value>jdbc:oracle:thin:@localhost:1521:nms</value>
            </parameter>
            <parameter>
                <name>username</name>
                <value>test</value>
            </parameter>
            <parameter>
                <name>password</name>
                <value>test</value>
            </parameter>
            <parameter>
                <name>maxActive</name>
                <value>20</value>
            </parameter>
            <parameter>
                <name>maxIdle</name>
                <value>10</value>
            </parameter>
            <parameter>
                <name>maxWait</name>
                <value>-1</value>
            </parameter>
            <parameter>
                    <name>removeAbandoned</name>
                    <value>true</value>
            </parameter>

            <parameter>
              <name>removeAbandonedTimeout</name>
              <value>200</value>
             </parameter>

            <parameter>
              <name>logAbandoned</name>
              <value>true</value>
            </parameter>

        </ResourceParams>

        </DefaultContext>

      <Host name="localhost" appBase="/home/smsc/proxy_nms/webapps"
unpackWARs="true" >

        <Context path="" docBase="/opt/tomcat/webapps/ROOT"
            reloadable="true" crossContext="true"
            debug="0" privileged="false" >

            <Logger className="org.apache.catalina.logger.FileLogger"
                    prefix="localhost_root_log." suffix=".txt"
                timestamp="true"/>
         </Context>

        <Context path="/proxy_nms" docBase="proxy_nms"
            reloadable="true" crossContext="true"
            debug="0" privileged="false" >


            <Logger className="org.apache.catalina.logger.FileLogger"
                    prefix="localhost_proxy_nms_log." suffix=".txt"
                timestamp="true"/>
         </Context>

      </Host>
    </Engine>
  </Service>
</Server>
Comment 1 Yoav Shapira 2004-08-11 16:45:41 UTC
This is what we get for adding convenience features like DefaultContext.  I 
recommend you stick to the Servlet Spec and declare the connection pool in your 
context element only, not in the DefaultContext.  The latter also has the 
undesirable side effect of creating one pool per context, so the total number 
of connections can be higher than you wanted.
Comment 2 Yoav Shapira 2004-08-30 20:41:42 UTC
This won't be fixed in Tomcat 5.0.x.  You should put the data source in the 
<Context> proper, not in <DefaultContext>.

To manually close the DataSource and/or its connections, do the normal JNDI 
lookup for it, e.g.
InitialContext ictx = new InitialContext();
DataSource ds = (DataSource) ictx.lookup("java:comp/env/jdbc/AdminDB");

Then cast to the DBCP-specific class, org.apache.commons.dbcp.BasicDataSource:
BasicDataSource bds = (BasicDataSource) ds;

And call bds.close().

If you have trouble with the above or in general, please use the tomcat-user 
mailing list to ask for help and discuss solutions.  Only post proven bugs with 
test cases to Bugzilla please.  Thank you ;)