Skip to content

Commit a7ca9a9

Browse files
authored
Merge pull request #615 from FortnoxAB/patch-4
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
2 parents 878d6ef + 52b67b2 commit a7ca9a9

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

rxnetty-common/src/main/java/io/reactivex/netty/client/pool/PoolConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class PoolConfig<W, R> {
3737

3838
public PoolConfig() {
3939
maxIdleTimeMillis = DEFAULT_MAX_IDLE_TIME_MILLIS;
40-
idleConnCleanupTicker = Observable.timer(maxIdleTimeMillis, TimeUnit.MILLISECONDS);
40+
idleConnCleanupTicker = Observable.interval(maxIdleTimeMillis, maxIdleTimeMillis, TimeUnit.MILLISECONDS);
4141
idleConnectionsHolder = new FIFOIdleConnectionsHolder<>();
4242
limitDeterminationStrategy = UnboundedPoolLimitDeterminationStrategy.INSTANCE;
4343
}

rxnetty-common/src/main/java/io/reactivex/netty/client/pool/PooledConnectionProviderImpl.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,19 @@ public PooledConnectionProviderImpl(PoolConfig<W, R> poolConfig, HostConnector<W
7070
limitDeterminationStrategy = poolConfig.getPoolLimitDeterminationStrategy();
7171
maxIdleTimeMillis = poolConfig.getMaxIdleTimeMillis();
7272
// In case, there is no cleanup required, this observable should never give a tick.
73-
idleConnCleanupSubscription = poolConfig.getIdleConnectionsCleanupTimer()
74-
.doOnError(LogErrorAction.INSTANCE)
75-
.retry() // Retry when there is an error in timer.
76-
.concatMap(new IdleConnectionCleanupTask())
77-
.onErrorResumeNext(new Func1<Throwable, Observable<Void>>() {
78-
@Override
79-
public Observable<Void> call(Throwable throwable) {
80-
logger.error("Ignoring error cleaning up idle connections.",
81-
throwable);
82-
return Observable.empty();
83-
}
84-
}).subscribe(Actions.empty()); // Errors are logged and ignored.
73+
idleConnCleanupSubscription = poolConfig.getIdleConnCleanupTicker()
74+
.doOnError(LogErrorAction.INSTANCE)
75+
.retry() // Retry when there is an error in timer.
76+
.concatMap(new IdleConnectionCleanupTask())
77+
.doOnError(new Action1<Throwable>() {
78+
@Override
79+
public void call(Throwable throwable) {
80+
logger.error("Ignoring error cleaning up idle connections.",
81+
throwable);
82+
}
83+
})
84+
.retry()
85+
.subscribe();
8586

8687
hostConnector.getHost()
8788
.getCloseNotifier()

0 commit comments

Comments
 (0)