diff --git a/Sources/SwiftKuery/ConnectionPool.swift b/Sources/SwiftKuery/ConnectionPool.swift index 832b7184..572a61a6 100644 --- a/Sources/SwiftKuery/ConnectionPool.swift +++ b/Sources/SwiftKuery/ConnectionPool.swift @@ -125,14 +125,15 @@ public class ConnectionPool { } item = pool[0] pool.removeFirst() - // Check if the item is alive, and append a new one to the pool if it isn't + // Check if the item is alive, and replace with a new one if it isn't if item.isConnected == false { releaser(item) capacity -= 1 - if let newItem = generator() { + if let replacementItem = generator() { capacity += 1 - pool.append(newItem) - semaphore.signal() + item = replacementItem + } else { + item = nil } } // If we took the last item, we can choose to grow the pool diff --git a/Sources/SwiftKuery/ConnectionPoolConnection.swift b/Sources/SwiftKuery/ConnectionPoolConnection.swift index 1c620201..9e531e55 100644 --- a/Sources/SwiftKuery/ConnectionPoolConnection.swift +++ b/Sources/SwiftKuery/ConnectionPoolConnection.swift @@ -66,7 +66,7 @@ public class ConnectionPoolConnection: Connection { /// An indication whether there is a connection to the database. public var isConnected: Bool { - return connection != nil + return connection?.isConnected ?? false } /// Execute a query.