Skip to content

Commit 27adb14

Browse files
committed
Make the pool create and fetch logic restricted to the _acquire method
1 parent 9f70650 commit 27adb14

File tree

1 file changed

+8
-9
lines changed
  • packages/bolt-connection/src/pool

1 file changed

+8
-9
lines changed

packages/bolt-connection/src/pool/pool.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ class Pool {
110110

111111
request = new PendingRequest(key, resolve, reject, timeoutId, this._log)
112112
allRequests[key].push(request)
113-
const pool = this._getOrInitializePoolFor(key)
114-
this._processPendingAcquireRequests(address, pool)
113+
this._processPendingAcquireRequests(address)
115114
})
116115
}
117116

@@ -206,7 +205,7 @@ class Pool {
206205
if (this._log.isDebugEnabled()) {
207206
this._log.debug(`${resource} acquired from the pool ${key}`)
208207
}
209-
return resource
208+
return { resource, pool }
210209
} else {
211210
await this._destroy(resource)
212211
}
@@ -220,7 +219,7 @@ class Pool {
220219
this.activeResourceCount(address) + this._pendingCreates[key]
221220
if (numConnections >= this._maxSize) {
222221
// Will put this request in queue instead since the pool is full
223-
return null
222+
return { resource: null, pool }
224223
}
225224
}
226225

@@ -239,7 +238,7 @@ class Pool {
239238
} finally {
240239
this._pendingCreates[key] = this._pendingCreates[key] - 1
241240
}
242-
return resource
241+
return { resource, pool }
243242
}
244243

245244
async _release (address, resource, pool) {
@@ -288,7 +287,7 @@ class Pool {
288287
}
289288
resourceReleased(key, this._activeResourceCounts)
290289

291-
this._processPendingAcquireRequests(address, pool)
290+
this._processPendingAcquireRequests(address)
292291
}
293292

294293
async _purgeKey (key) {
@@ -306,7 +305,7 @@ class Pool {
306305
}
307306
}
308307

309-
_processPendingAcquireRequests (address, pool) {
308+
_processPendingAcquireRequests (address) {
310309
const key = address.asKey()
311310
const requests = this._acquireRequests[key]
312311
if (requests) {
@@ -318,9 +317,9 @@ class Pool {
318317
// failed to acquire/create a new connection to resolve the pending acquire request
319318
// propagate the error by failing the pending request
320319
pendingRequest.reject(error)
321-
return null
320+
return { resource: null }
322321
})
323-
.then(resource => {
322+
.then(({ resource, pool }) => {
324323
if (resource) {
325324
// managed to acquire a valid resource from the pool
326325

0 commit comments

Comments
 (0)