Skip to content

Commit 5df6f96

Browse files
ronagmetcoder95
authored andcommitted
fix: pool busy (nodejs#1151)
1 parent 316c2ee commit 5df6f96

File tree

4 files changed

+12
-16
lines changed

4 files changed

+12
-16
lines changed

lib/balanced-pool.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const {
99
kNeedDrain,
1010
kAddClient,
1111
kRemoveClient,
12-
kDispatch
12+
kGetDispatcher
1313
} = require('./pool-base')
1414
const Pool = require('./pool')
1515
const { kUrl } = require('./core/symbols')
@@ -65,7 +65,7 @@ class BalancedPool extends PoolBase {
6565
.map((p) => p[kUrl].origin)
6666
}
6767

68-
[kDispatch] () {
68+
[kGetDispatcher] () {
6969
// We validate that pools is greater than 0,
7070
// otherwise we would have to wait until an upstream
7171
// is added, which might never happen.

lib/pool-base.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const kOnConnect = Symbol('onConnect')
2020
const kOnDisconnect = Symbol('onDisconnect')
2121
const kOnConnectionError = Symbol('onConnectionError')
2222
const kQueued = Symbol('queued')
23-
const kDispatch = Symbol('dispatch')
23+
const kGetDispatcher = Symbol('get dispatcher')
2424
const kAddClient = Symbol('add client')
2525
const kRemoveClient = Symbol('remove client')
2626

@@ -190,19 +190,15 @@ class PoolBase extends Dispatcher {
190190
throw new ClientClosedError()
191191
}
192192

193-
const dispatcher = this[kDispatch]()
193+
const dispatcher = this[kGetDispatcher]()
194194

195195
if (!dispatcher) {
196196
this[kNeedDrain] = true
197197
this[kQueue].push({ opts, handler })
198198
this[kQueued]++
199199
} else if (!dispatcher.dispatch(opts, handler)) {
200200
dispatcher[kNeedDrain] = true
201-
this[kNeedDrain] = this[kClients].some(dispatcher => (
202-
!dispatcher[kNeedDrain] &&
203-
dispatcher.closed !== true &&
204-
dispatcher.destroyed !== true
205-
))
201+
this[kNeedDrain] = !this[kGetDispatcher]()
206202
}
207203
} catch (err) {
208204
if (typeof handler.onError !== 'function') {
@@ -257,5 +253,5 @@ module.exports = {
257253
kNeedDrain,
258254
kAddClient,
259255
kRemoveClient,
260-
kDispatch
256+
kGetDispatcher
261257
}

lib/pool.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const {
55
kClients,
66
kNeedDrain,
77
kAddClient,
8-
kDispatch
8+
kGetDispatcher
99
} = require('./pool-base')
1010
const Client = require('./client')
1111
const {
@@ -64,7 +64,7 @@ class Pool extends PoolBase {
6464
this[kFactory] = factory
6565
}
6666

67-
[kDispatch] () {
67+
[kGetDispatcher] () {
6868
let dispatcher = this[kClients].find(dispatcher => !dispatcher[kNeedDrain])
6969

7070
if (dispatcher) {

test/pool.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,11 @@ test('backpressure algorithm', (t) => {
321321

322322
writeMore = true
323323

324-
d4.client.emit('drain', new URL('http://notahost'))
324+
d4.client.emit('drain', new URL('http://notahost'), [])
325325

326326
pool.dispatch({}, noopHandler) // d5 = c1
327327

328-
d3.client.emit('drain', new URL('http://notahost'))
328+
d3.client.emit('drain', new URL('http://notahost'), [])
329329

330330
pool.dispatch({}, noopHandler) // d6 = c0
331331

@@ -337,7 +337,7 @@ test('backpressure algorithm', (t) => {
337337
t.equal(d5.id, d4.id)
338338
t.equal(d3.id, d6.id)
339339

340-
t.equal(total, 2)
340+
t.equal(total, 3)
341341

342342
t.end()
343343
})
@@ -380,7 +380,7 @@ test('busy', (t) => {
380380
})
381381
})
382382
t.equal(client[kPending], n)
383-
t.equal(client[kBusy], n > 2)
383+
t.equal(client[kBusy], n > 1)
384384
t.equal(client[kSize], n)
385385
t.equal(client[kRunning], 0)
386386
}

0 commit comments

Comments
 (0)