tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 33938] New: - org.apache.catalina.realm.DataSourceRealm.getRoles() does not close the Connection it allocated
Date Wed, 09 Mar 2005 19:28:06 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=33938>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=33938

           Summary: org.apache.catalina.realm.DataSourceRealm.getRoles()
                    does not close the Connection it allocated
           Product: Tomcat 5
           Version: 5.5.7
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Catalina
        AssignedTo: tomcat-dev@jakarta.apache.org
        ReportedBy: d.tonhofer@m-plify.com


I'm seeing quick resource exhaustion if a Realm uses pooled connections
using DataSourceRealm. I checked whether every 'open' was correctly followed
by a close. In org.apache.catalina.realm.DataSourceRealm.getRoles(), one
finds code that seems to miss something:

   /**
     * Return the roles associated with the gven user name.
     */
    protected ArrayList getRoles(String username) {

        ResultSet rs = null;
        PreparedStatement stmt = null;
        Connection dbConnection = null;

        // Ensure that we have an open database connection
        dbConnection = open();
        if (dbConnection == null) {
            return null;
        }

        try {
            // Accumulate the user's roles
            ArrayList list = new ArrayList();
            stmt = roles(dbConnection, username);
            rs = stmt.executeQuery();
            while (rs.next()) {
                String role = rs.getString(1);
                if (role != null) {
                    list.add(role.trim());
                }
            }
            
            return (list);
        } catch(SQLException e) {
        	container.getLogger().error(sm
	                .getString("datasourceRealm.getRoles.exception",
	        		           username));
        } finally {
        	try {
	            if (rs != null) {
	                rs.close();
	            }
	            if (stmt != null) {
	                stmt.close();
	            }
            } catch(SQLException e) {
            	container.getLogger().error(sm
    	                .getString("datasourceRealm.getRoles.exception",
    	        		           username));
        	}
        }

        return (null);
    }


The 'finally' of getPassword() looks better:


} finally {
        	try {
	            if (rs != null) {
	                rs.close();
	            }
	            if (stmt != null) {
	                stmt.close();
	            }
	            if( !dbConnection.getAutoCommit() ) {
	                dbConnection.commit();             
	            }
        	} catch (SQLException e) {
            	container.getLogger().error(sm
                        .getString("datasourceRealm.getPassword.exception",
        		                   username));
        		
        	}
            // Release the database connection we just used
            close(dbConnection);
            dbConnection = null;

        }

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message