mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fixed for removeAbandonded concurrent problem
This commit is contained in:
@@ -796,7 +796,10 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
if (exceptionSorter != null && exceptionSorter.isExceptionFatal(sqlEx)) {
|
||||
if (pooledConnection.isTraceEnable()) {
|
||||
synchronized (activeConnections) {
|
||||
activeConnections.remove(pooledConnection);
|
||||
if (pooledConnection.isTraceEnable()) {
|
||||
activeConnections.remove(pooledConnection);
|
||||
pooledConnection.setTraceEnable(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.discardConnection(holder.getConnection());
|
||||
@@ -824,11 +827,14 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
|
||||
if (pooledConnection.isTraceEnable()) {
|
||||
synchronized (activeConnections) {
|
||||
Object oldInfo = activeConnections.remove(pooledConnection);
|
||||
if (oldInfo == null) {
|
||||
if (LOG.isWarnEnabled()) {
|
||||
LOG.warn("remove abandonded failed. activeConnections.size " + activeConnections.size());
|
||||
if (pooledConnection.isTraceEnable()) {
|
||||
Object oldInfo = activeConnections.remove(pooledConnection);
|
||||
if (oldInfo == null) {
|
||||
if (LOG.isWarnEnabled()) {
|
||||
LOG.warn("remove abandonded failed. activeConnections.size " + activeConnections.size());
|
||||
}
|
||||
}
|
||||
pooledConnection.setTraceEnable(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1320,6 +1326,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
|
||||
if (timeMillis >= removeAbandonedTimeoutMillis) {
|
||||
iter.remove();
|
||||
pooledConnection.setTraceEnable(false);
|
||||
abandonedList.add(pooledConnection);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public class DruidPooledConnection implements javax.sql.PooledConnection, Connec
|
||||
protected volatile DruidConnectionHolder holder;
|
||||
protected TransactionInfo transactionInfo;
|
||||
private final boolean dupCloseLogEnable;
|
||||
private boolean traceEnable = false;
|
||||
private volatile boolean traceEnable = false;
|
||||
private boolean disable = false;
|
||||
private boolean closed = false;
|
||||
private final Thread ownerThread;
|
||||
@@ -212,6 +212,40 @@ public class DruidPooledConnection implements javax.sql.PooledConnection, Connec
|
||||
return;
|
||||
}
|
||||
|
||||
if (holder.getDataSource().isRemoveAbandoned()) {
|
||||
syncClose();
|
||||
return;
|
||||
}
|
||||
|
||||
for (ConnectionEventListener listener : holder.getConnectionEventListeners()) {
|
||||
listener.connectionClosed(new ConnectionEvent(this));
|
||||
}
|
||||
|
||||
DruidAbstractDataSource dataSource = holder.getDataSource();
|
||||
List<Filter> filters = dataSource.getProxyFilters();
|
||||
if (filters.size() > 0) {
|
||||
FilterChainImpl filterChain = new FilterChainImpl(dataSource);
|
||||
filterChain.dataSource_recycle(this);
|
||||
} else {
|
||||
recycle();
|
||||
}
|
||||
|
||||
this.disable = true;
|
||||
}
|
||||
|
||||
public synchronized void syncClose() throws SQLException {
|
||||
if (this.disable) {
|
||||
return;
|
||||
}
|
||||
|
||||
DruidConnectionHolder holder = this.holder;
|
||||
if (holder == null) {
|
||||
if (dupCloseLogEnable) {
|
||||
LOG.error("dup close");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
for (ConnectionEventListener listener : holder.getConnectionEventListeners()) {
|
||||
listener.connectionClosed(new ConnectionEvent(this));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user