Revert "If the user is calling setNetworkTImeout() and specifying their own Executor instance, we need to "restore" their Executor instance whenever we "reset" the network timeout after modifying it for the duration of HikariCP internal methods (for example in the isConnectionAlive() check)."

This reverts commit 8ad630643b.
pull/333/head
Brett Wooldridge 10 years ago
parent b7253d18ed
commit 27b7f5a34e

@ -192,7 +192,7 @@ public class HikariPool implements HikariPoolMBean, IBagStateListener
} }
final long now = clockSource.currentTime(); final long now = clockSource.currentTime();
if (bagEntry.evicted || (clockSource.elapsedMillis(bagEntry.lastAccess, now) > ALIVE_BYPASS_WINDOW_MS && !isConnectionAlive(bagEntry))) { if (bagEntry.evicted || (clockSource.elapsedMillis(bagEntry.lastAccess, now) > ALIVE_BYPASS_WINDOW_MS && !isConnectionAlive(bagEntry.connection))) {
closeConnection(bagEntry, "connection evicted or dead"); // Throw away the dead connection and try again closeConnection(bagEntry, "connection evicted or dead"); // Throw away the dead connection and try again
timeout = hardTimeout - clockSource.elapsedMillis(startTime, now); timeout = hardTimeout - clockSource.elapsedMillis(startTime, now);
} }
@ -508,7 +508,7 @@ public class HikariPool implements HikariPoolMBean, IBagStateListener
transactionIsolation = (transactionIsolation < 0 ? connection.getTransactionIsolation() : transactionIsolation); transactionIsolation = (transactionIsolation < 0 ? connection.getTransactionIsolation() : transactionIsolation);
poolUtils.setupConnection(connection, config.getConnectionInitSql(), isAutoCommit, isReadOnly, transactionIsolation, catalog); poolUtils.setupConnection(connection, config.getConnectionInitSql(), isAutoCommit, isReadOnly, transactionIsolation, catalog);
poolUtils.setNetworkTimeout(connection, originalTimeout, null); poolUtils.setNetworkTimeout(connection, originalTimeout);
connectionBag.add(new PoolBagEntry(connection, this)); connectionBag.add(new PoolBagEntry(connection, this));
lastConnectionFailure.set(null); lastConnectionFailure.set(null);
@ -549,14 +549,14 @@ public class HikariPool implements HikariPoolMBean, IBagStateListener
/** /**
* Check whether the connection is alive or not. * Check whether the connection is alive or not.
* *
* @param bagEntry a PoolBagEntry containing a connection to test * @param connection the connection to test
* @return true if the connection is alive, false if it is not alive or we timed out * @return true if the connection is alive, false if it is not alive or we timed out
*/ */
private boolean isConnectionAlive(final PoolBagEntry bagEntry) private boolean isConnectionAlive(final Connection connection)
{ {
final Connection connection = bagEntry.connection;
final int timeoutSec = (int) TimeUnit.MILLISECONDS.toSeconds(validationTimeout);
try { try {
int timeoutSec = (int) TimeUnit.MILLISECONDS.toSeconds(validationTimeout);
if (isUseJdbc4Validation) { if (isUseJdbc4Validation) {
return connection.isValid(timeoutSec); return connection.isValid(timeoutSec);
} }
@ -574,7 +574,7 @@ public class HikariPool implements HikariPoolMBean, IBagStateListener
connection.rollback(); connection.rollback();
} }
poolUtils.setNetworkTimeout(connection, originalTimeout, bagEntry.clientExecutor); poolUtils.setNetworkTimeout(connection, originalTimeout);
return true; return true;
} }

@ -17,7 +17,6 @@ package com.zaxxer.hikari.pool;
import java.sql.Connection; import java.sql.Connection;
import java.sql.Statement; import java.sql.Statement;
import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -43,7 +42,6 @@ public final class PoolBagEntry implements IConcurrentBagEntry
public volatile long lastOpenTime; public volatile long lastOpenTime;
public volatile boolean evicted; public volatile boolean evicted;
public volatile boolean aborted; public volatile boolean aborted;
public volatile Executor clientExecutor;
private volatile ScheduledFuture<?> endOfLife; private volatile ScheduledFuture<?> endOfLife;

@ -30,12 +30,13 @@ public final class PoolUtilities
private static final Logger LOGGER = LoggerFactory.getLogger(PoolUtilities.class); private static final Logger LOGGER = LoggerFactory.getLogger(PoolUtilities.class);
private Executor netTimeoutExecutor; private Executor netTimeoutExecutor;
private final HikariConfig config; private final HikariConfig config;
private final String poolName; private final String poolName;
private boolean isNetworkTimeoutSupported;
private boolean isQueryTimeoutSupported;
private volatile boolean isValidChecked; private volatile boolean isValidChecked;
private volatile boolean isValidSupported; private volatile boolean isValidSupported;
private boolean isNetworkTimeoutSupported;
private boolean isQueryTimeoutSupported;
public PoolUtilities(final HikariConfig configuration) public PoolUtilities(final HikariConfig configuration)
{ {
@ -62,7 +63,7 @@ public final class PoolUtilities
LOGGER.debug("Closing connection {} in pool {}{}", connection, poolName, addendum); LOGGER.debug("Closing connection {} in pool {}{}", connection, poolName, addendum);
try { try {
setNetworkTimeout(connection, TimeUnit.SECONDS.toMillis(15), netTimeoutExecutor); setNetworkTimeout(connection, TimeUnit.SECONDS.toMillis(15));
} }
finally { finally {
// continue with the close even if setNetworkTimeout() throws (due to driver poorly behaving drivers) // continue with the close even if setNetworkTimeout() throws (due to driver poorly behaving drivers)
@ -205,13 +206,12 @@ public final class PoolUtilities
* *
* @param connection the connection to set the network timeout on * @param connection the connection to set the network timeout on
* @param timeoutMs the number of milliseconds before timeout * @param timeoutMs the number of milliseconds before timeout
* @param executor a specified Executor to use, or null for the pool-defined Executor
* @throws SQLException throw if the connection.setNetworkTimeout() call throws * @throws SQLException throw if the connection.setNetworkTimeout() call throws
*/ */
public void setNetworkTimeout(final Connection connection, final long timeoutMs, final Executor executor) throws SQLException public void setNetworkTimeout(final Connection connection, final long timeoutMs) throws SQLException
{ {
if (isNetworkTimeoutSupported) { if (isNetworkTimeoutSupported) {
connection.setNetworkTimeout((executor == null) ? netTimeoutExecutor : executor, (int) timeoutMs); connection.setNetworkTimeout(netTimeoutExecutor, (int) timeoutMs);
} }
} }

@ -25,7 +25,6 @@ import java.sql.Statement;
import java.sql.Wrapper; import java.sql.Wrapper;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.concurrent.Executor;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -377,14 +376,6 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy
isCatalogDirty = (catalog != null && !catalog.equals(bagEntry.parentPool.catalog)) || (catalog == null && bagEntry.parentPool.catalog != null); isCatalogDirty = (catalog != null && !catalog.equals(bagEntry.parentPool.catalog)) || (catalog == null && bagEntry.parentPool.catalog != null);
} }
/** {@inheritDoc} */
@Override
public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException
{
delegate.setNetworkTimeout(executor, milliseconds);
bagEntry.clientExecutor = executor;
}
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public final boolean isWrapperFor(Class<?> iface) throws SQLException public final boolean isWrapperFor(Class<?> iface) throws SQLException

Loading…
Cancel
Save