@@ -52,18 +52,15 @@ public actor PostgresConnectionPool {
5252 self . onReturnConnection = configuration. onReturnConnection
5353 self . onCloseConnection = configuration. onCloseConnection
5454
55- var postgresConnection = PostgresConnection . Configuration. Connection (
55+ var postgresConfiguration = PostgresConnection . Configuration (
5656 host: configuration. connection. host,
57- port: configuration. connection. port)
58- postgresConnection. connectTimeout = . seconds( Int64 ( configuration. connectTimeout) )
59-
60- self . postgresConfiguration = PostgresConnection . Configuration (
61- connection: postgresConnection,
62- authentication: . init(
63- username: configuration. connection. username,
64- database: configuration. connection. database,
65- password: configuration. connection. password) ,
57+ port: configuration. connection. port,
58+ username: configuration. connection. username,
59+ password: configuration. connection. password,
60+ database: configuration. connection. database,
6661 tls: . disable)
62+ postgresConfiguration. options. connectTimeout = . seconds( Int64 ( configuration. connectTimeout) )
63+ self . postgresConfiguration = postgresConfiguration
6764 }
6865
6966 deinit {
@@ -124,8 +121,12 @@ public actor PostgresConnectionPool {
124121 }
125122
126123 func releaseConnection( _ connection: PoolConnection ) async {
127- connection. state = . available
128- available. append ( connection)
124+ // It can happen that the connection is returned before it's being used
125+ // (e.g. on cancellation)
126+ if connection. state != . available {
127+ connection. state = . available
128+ available. append ( connection)
129+ }
129130
130131 Task . detached { [ weak self] in
131132 await self ? . handleNextContinuation ( )
@@ -169,7 +170,7 @@ public actor PostgresConnectionPool {
169170 }
170171
171172 // Shut down the event loop.
172- try ? eventLoopGroup. syncShutdownGracefully ( )
173+ try ? await eventLoopGroup. shutdownGracefully ( )
173174 }
174175
175176 // MARK: - Private
@@ -191,7 +192,8 @@ public actor PostgresConnectionPool {
191192
192193 // TODO: Kill self if too many stuck connections
193194
194- logger. debug ( " [ \( poolName) ] Check connections: \( continuations. count) continuations left, \( connections. count) connections, \( available. count) available " )
195+ let usageCounter = connections. reduce ( 0 ) { $0 + $1. usageCounter }
196+ logger. info ( " [ \( poolName) ] \( connections. count) connections ( \( available. count) available, \( usageCounter) queries), \( continuations. count) continuations left " )
195197
196198 // Check for waiting continuations and open a new connection if possible
197199 if connections. count < poolSize,
0 commit comments