@@ -69,11 +69,18 @@ class Pool {
69
69
const key = address . asKey ( )
70
70
71
71
if ( resource ) {
72
- resourceAcquired ( key , this . _activeResourceCounts )
73
- if ( this . _log . isDebugEnabled ( ) ) {
74
- this . _log . debug ( `${ resource } acquired from the pool ${ key } ` )
72
+ if (
73
+ this . _maxSize &&
74
+ this . activeResourceCount ( address ) >= this . _maxSize
75
+ ) {
76
+ this . _destroy ( resource )
77
+ } else {
78
+ resourceAcquired ( key , this . _activeResourceCounts )
79
+ if ( this . _log . isDebugEnabled ( ) ) {
80
+ this . _log . debug ( `${ resource } acquired from the pool ${ key } ` )
81
+ }
82
+ return resource
75
83
}
76
- return resource
77
84
}
78
85
79
86
// We're out of resources and will try to acquire later on when an existing resource is released.
@@ -100,11 +107,11 @@ class Pool {
100
107
// request already resolved/rejected by the release operation; nothing to do
101
108
} else {
102
109
// request is still pending and needs to be failed
110
+ const activeCount = this . activeResourceCount ( address )
111
+ const idleCount = this . has ( address ) ? this . _pools [ key ] . length : 0
103
112
request . reject (
104
113
newError (
105
- `Connection acquisition timed out in ${
106
- this . _acquisitionTimeout
107
- } ms.`
114
+ `Connection acquisition timed out in ${ this . _acquisitionTimeout } ms. Poos status: Active conn count = ${ activeCount } , Idle conn count = ${ idleCount } .`
108
115
)
109
116
)
110
117
}
@@ -209,7 +216,10 @@ class Pool {
209
216
}
210
217
if ( this . _installIdleObserver ) {
211
218
this . _installIdleObserver ( resource , {
212
- onError : ( ) => {
219
+ onError : error => {
220
+ this . _log . debug (
221
+ `Idle connection ${ resource } destroyed because of error: ${ error } `
222
+ )
213
223
const pool = this . _pools [ key ]
214
224
if ( pool ) {
215
225
this . _pools [ key ] = pool . filter ( r => r !== resource )
0 commit comments