Skip to content

Commit f45e68d

Browse files
committed
thread pool fix
1 parent 2a195b4 commit f45e68d

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/domain/thread-pool.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ export class ThreadPool extends EventEmitter {
366366
async stopThread (thread, reason) {
367367
const exitCode = await thread.stop()
368368
this.freeThreads.splice(this.freeThreads.indexOf(thread), 1)
369-
this.threads.splice(this.freeThreads.indexOf(thread), 1)
369+
this.threads.splice(this.threads.indexOf(thread), 1)
370370
return { pool: this.name, id: thread.id, exitCode, reason }
371371
}
372372

@@ -450,8 +450,16 @@ export class ThreadPool extends EventEmitter {
450450
return this
451451
}
452452

453-
growPool () {
454-
if (this.capacityAvailable()) return this.startThread()
453+
async growPool () {
454+
if (this.capacityAvailable()) {
455+
const thread = await this.startThread()
456+
if (this.capacityAvailable())
457+
broker.on(this.growPool.name, this.growPool, {
458+
singleton: true,
459+
once: true
460+
})
461+
return thread
462+
}
455463
}
456464

457465
jobQueueRate () {
@@ -588,6 +596,11 @@ export class ThreadPool extends EventEmitter {
588596
)
589597
return thread
590598
}
599+
// none free, try to allocate
600+
const thread = this.allocate()
601+
// pop this one
602+
if (thread) this.freeThreads.pop()
603+
// dont return tyhread, let queued jobs go
591604
}
592605

593606
checkin (thread) {

0 commit comments

Comments
 (0)