Skip to content

Commit

Permalink
Merge pull request #615 from FortnoxAB/patch-4
Browse files Browse the repository at this point in the history
Interval instead of timer for the idleConnectionCleanup so that it keep cleaning up. Add retry so that a failure during cleanup will not stop future cleanups
  • Loading branch information
jamesgorman2 authored Feb 14, 2019
2 parents 878d6ef + 52b67b2 commit a7ca9a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class PoolConfig<W, R> {

public PoolConfig() {
maxIdleTimeMillis = DEFAULT_MAX_IDLE_TIME_MILLIS;
idleConnCleanupTicker = Observable.timer(maxIdleTimeMillis, TimeUnit.MILLISECONDS);
idleConnCleanupTicker = Observable.interval(maxIdleTimeMillis, maxIdleTimeMillis, TimeUnit.MILLISECONDS);
idleConnectionsHolder = new FIFOIdleConnectionsHolder<>();
limitDeterminationStrategy = UnboundedPoolLimitDeterminationStrategy.INSTANCE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,19 @@ public PooledConnectionProviderImpl(PoolConfig<W, R> poolConfig, HostConnector<W
limitDeterminationStrategy = poolConfig.getPoolLimitDeterminationStrategy();
maxIdleTimeMillis = poolConfig.getMaxIdleTimeMillis();
// In case, there is no cleanup required, this observable should never give a tick.
idleConnCleanupSubscription = poolConfig.getIdleConnectionsCleanupTimer()
.doOnError(LogErrorAction.INSTANCE)
.retry() // Retry when there is an error in timer.
.concatMap(new IdleConnectionCleanupTask())
.onErrorResumeNext(new Func1<Throwable, Observable<Void>>() {
@Override
public Observable<Void> call(Throwable throwable) {
logger.error("Ignoring error cleaning up idle connections.",
throwable);
return Observable.empty();
}
}).subscribe(Actions.empty()); // Errors are logged and ignored.
idleConnCleanupSubscription = poolConfig.getIdleConnCleanupTicker()
.doOnError(LogErrorAction.INSTANCE)
.retry() // Retry when there is an error in timer.
.concatMap(new IdleConnectionCleanupTask())
.doOnError(new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
logger.error("Ignoring error cleaning up idle connections.",
throwable);
}
})
.retry()
.subscribe();

hostConnector.getHost()
.getCloseNotifier()
Expand Down

0 comments on commit a7ca9a9

Please sign in to comment.