Skip to content

Commit c8cb256

Browse files
committed
Add default buffer connectionRetryTimeout to avoid literal immediate timeouts
Motivation: When trying to allow users to configure the connection retry timeout offset, not having a value provided (deadline of `now`) caused all attempts to use the pool to fail. Modifications: - Change: RedisConnectionPool to always have a timeout offset defined Result: If users don't specify any value, then the default of 60 seconds will be used. If users specify "nil" (or `.none`) as the timeout, then a minimum of 10 milliseconds will be used to avoid immediate timeouts Otherwise, use the user's specified `TimeAmount` as the offset of the timeout
1 parent 3e28e75 commit c8cb256

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

Sources/RediStack/RedisConnectionPool.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class RedisConnectionPool {
4545
/// This needs to be a var because we reuse the same connection
4646
private var pubsubConnection: RedisConnection?
4747

48-
private let connectionRetryTimeout: TimeAmount?
48+
private let connectionRetryTimeout: TimeAmount
4949
private let connectionPassword: String?
5050
private let connectionSystemContext: Logger
5151
private let poolSystemContext: Context
@@ -88,7 +88,7 @@ public class RedisConnectionPool {
8888
self.loop = loop
8989
self.serverConnectionAddresses = ConnectionAddresses(initialAddresses: serverConnectionAddresses)
9090
self.connectionPassword = connectionPassword
91-
self.connectionRetryTimeout = connectionRetryTimeout
91+
self.connectionRetryTimeout = connectionRetryTimeout ?? .milliseconds(10)
9292

9393
// mix of terminology here with the loggers
9494
// as we're being "forward thinking" in terms of the 'baggage context' future type
@@ -392,11 +392,7 @@ extension RedisConnectionPool: RedisClientWithUserContext {
392392
let logger = self.prepareLoggerForUse(context)
393393

394394
guard let connection = preferredConnection else {
395-
return pool
396-
.leaseConnection(
397-
deadline: self.connectionRetryTimeout.map({ .now() + $0 }) ?? .now(),
398-
logger: logger
399-
)
395+
return pool.leaseConnection(deadline: .now() + self.connectionRetryTimeout, logger: logger)
400396
.flatMap { operation($0, pool.returnConnection(_:logger:), logger) }
401397
}
402398

0 commit comments

Comments
 (0)