Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 31 additions & 20 deletions lib/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,30 +410,41 @@ const poolModule = (() => {
}

async function grow () {
const toPromise = []
const existing = idle.length + busyConnectionCount + pendingCreates + parkingConnectionCount
if (!killed) {
for (let i = existing; i < options.ceiling; ++i) {
++pendingCreates
toPromise.push(openPromise(options.connectionString))
}
if (killed) {
return
}
const res = await Promise.all(toPromise)
if (res.length === 0) {
const existing = idle.length + busyConnectionCount + pendingCreates + parkingConnectionCount

if (existing === options.ceiling) {
return
}

const toPromise = []
for (let i = existing; i < options.ceiling; ++i) {
++pendingCreates
toPromise.push(openPromise(options.connectionString)
.then(
c => {
--pendingCreates
c.setSharedCache(poolProcedureCache, poolTableCache)
if (options.useUTC === true || options.useUTC === false) {
c.setUseUTC(options.useUTC)
}
if (options.useNumericString === true || options.useNumericString === false) {
c.setUseNumericString(options.useUTC)
}
checkin('grow', getDescription(c))
},
e => {
--pendingCreates
return Promise.reject(e)
}
)
)
}

const res = await Promise.all(toPromise)
_this.emit('debug', `grow creates ${res.length} connections for pool idle = ${idle.length}, busy = ${busyConnectionCount}, pending = ${pendingCreates}, parkingConnectionCount = ${parkingConnectionCount}, existing = ${existing}`)
res.forEach(c => {
c.setSharedCache(poolProcedureCache, poolTableCache)
if (options.useUTC === true || options.useUTC === false) {
c.setUseUTC(options.useUTC)
}
if (options.useNumericString === true || options.useNumericString === false) {
c.setUseNumericString(options.useUTC)
}
checkin('grow', getDescription(c))
--pendingCreates
})
}

function open (cb) {
Expand Down