[
https://issues.apache.org/jira/browse/FTPSERVER-453?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13891236#comment-13891236
]
Ken Kress edited comment on FTPSERVER-453 at 2/4/14 9:29 PM:
-------------------------------------------------------------
/* These are the changes I applied to selectUserByName. They seem to have
solved my problem.
I think it makes sense to make similar changes in each method that uses the
datasource.
*/
private BaseUser selectUserByName(String name) throws SQLException {
// create sql query
HashMap<String, Object> map = new HashMap<String, Object>();
map.put(ATTR_LOGIN, escapeString(name));
String sql = StringUtils.replaceString(selectUserStmt, map);
LOG.info(sql);
Statement stmt = null;
ResultSet rs = null;
Connection con = null; // Added
try {
// execute query
con = createConnection(); // Added
stmt = con.createStatement();
rs = stmt.executeQuery(sql);
// populate user object
BaseUser thisUser = null;
if (rs.next()) {
thisUser = new BaseUser();
thisUser.setName(rs.getString(ATTR_LOGIN));
thisUser.setPassword(rs.getString(ATTR_PASSWORD));
thisUser.setHomeDirectory(rs.getString(ATTR_HOME));
thisUser.setEnabled(rs.getBoolean(ATTR_ENABLE));
thisUser.setMaxIdleTime(rs.getInt(ATTR_MAX_IDLE_TIME));
List<Authority> authorities = new ArrayList<Authority>();
if (rs.getBoolean(ATTR_WRITE_PERM)) {
authorities.add(new WritePermission());
}
authorities.add(new ConcurrentLoginPermission(rs
.getInt(ATTR_MAX_LOGIN_NUMBER), rs
.getInt(ATTR_MAX_LOGIN_PER_IP)));
authorities.add(new TransferRatePermission(rs
.getInt(ATTR_MAX_DOWNLOAD_RATE), rs
.getInt(ATTR_MAX_UPLOAD_RATE)));
thisUser.setAuthorities(authorities);
}
rs.close(); rs = null; // Added
stmt.close(); stmt = null; // Added
con.close(); con = null; // Added
return thisUser;
} finally {
closeQuitely(rs);
closeQuitely(stmt);
}
}
was (Author: kkress2000):
/* These are the changes I applied to selectUserByName. They seem to have
solved my problem.
I think it makes sense to make similar changes in each method that uses the
datasource.
*/
private BaseUser selectUserByName(String name) throws SQLException {
// create sql query
HashMap<String, Object> map = new HashMap<String, Object>();
map.put(ATTR_LOGIN, escapeString(name));
String sql = StringUtils.replaceString(selectUserStmt, map);
LOG.info(sql);
Statement stmt = null;
ResultSet rs = null;
Connection con = null; // Added
try {
// execute query
con = createConnection(); // Added
stmt = con.createStatement();
rs = stmt.executeQuery(sql);
// populate user object
BaseUser thisUser = null;
if (rs.next()) {
thisUser = new BaseUser();
thisUser.setName(rs.getString(ATTR_LOGIN));
thisUser.setPassword(rs.getString(ATTR_PASSWORD));
thisUser.setHomeDirectory(rs.getString(ATTR_HOME));
thisUser.setEnabled(rs.getBoolean(ATTR_ENABLE));
thisUser.setMaxIdleTime(rs.getInt(ATTR_MAX_IDLE_TIME));
List<Authority> authorities = new ArrayList<Authority>();
if (rs.getBoolean(ATTR_WRITE_PERM)) {
authorities.add(new WritePermission());
}
authorities.add(new ConcurrentLoginPermission(rs
.getInt(ATTR_MAX_LOGIN_NUMBER), rs
.getInt(ATTR_MAX_LOGIN_PER_IP)));
authorities.add(new TransferRatePermission(rs
.getInt(ATTR_MAX_DOWNLOAD_RATE), rs
.getInt(ATTR_MAX_UPLOAD_RATE)));
thisUser.setAuthorities(authorities);
}
rs.close(); rs = null; // Added
stmt.close(); stmt = null; // Added
con.close(); con = null; // Added
return thisUser;
} finally {
closeQuitely(rs);
closeQuitely(stmt);
}
}
> pooled db connections not being closed
> --------------------------------------
>
> Key: FTPSERVER-453
> URL: https://issues.apache.org/jira/browse/FTPSERVER-453
> Project: FtpServer
> Issue Type: Bug
> Components: Core
> Affects Versions: 1.0.6
> Environment: ftpserver running in Tomcat on Windows and Linux using a
> JNDI datasource
> Reporter: Ken Kress
> Priority: Minor
>
> I set maxActive to 10 and started getting errors while testing. The log
> showed that I was running out of connections, which lead me to believe the
> connections were not being closed. I could not find a problem in the source
> code, but as I played around with it I inadvertently created a new problem
> ... I double closed a connection in DbUserManager.selectUserByName and got
> errors from DbUserManager.authenticate. Researching this new problem, I found
> a solution to both:
> http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html#Random_Connection_Closed_Exceptions.
> I'm not sure why this applies, but I no longer have abandoned connections
> being reclaimed.
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)