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