## [Unreleased]
+### Fixed
+
+- Ensure the minimum number of workers on a started pool is guaranteed.
+
## [3.1.27] - 2024-03-27
### Fixed
resolution: {integrity: sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w==}
dev: true
- /@types/mime@3.0.4:
- resolution: {integrity: sha512-iJt33IQnVRkqeqC7PzBHPTC6fDlRNRW8vjrgqtScAhrmMwe8c4Eo7+fUGTa+XdWrpEgpyKWMYmi2dIwMAYRzPw==}
+ /@types/mime@4.0.0:
+ resolution: {integrity: sha512-5eEkJZ/BLvTE3vXGKkWlyTSUVZuzj23Wj8PoyOq2lt5I3CYbiLBOPb3XmCW6QcuOibIUE6emHXHt9E/F/rCa6w==}
+ deprecated: This is a stub types definition. mime provides its own type definitions, so you do not need this installed.
+ dependencies:
+ mime: 4.0.1
dev: true
/@types/minimatch@5.1.2:
resolution: {integrity: sha512-PDRk21MnK70hja/YF8AHfC7yIsiQHn1rcXx7ijCFBX/k+XQJhQT/gw3xekXKJvx+5SXaMMS8oqQy09Mzvz2TuQ==}
dependencies:
'@types/http-errors': 2.0.4
- '@types/mime': 3.0.4
+ '@types/mime': 4.0.0
'@types/node': 20.12.2
dev: true
hasBin: true
dev: false
+ /mime@4.0.1:
+ resolution: {integrity: sha512-5lZ5tyrIfliMXzFtkYyekWbtRXObT9OWa8IwQ5uxTBDHucNNwniRqo0yInflj+iYi5CBa6qxadGzGarDfuEOxA==}
+ engines: {node: '>=16'}
+ hasBin: true
+ dev: true
+
/minimatch@3.1.2:
resolution: {integrity: sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==}
dependencies:
resolution: {integrity: sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w==}
dev: true
- /@types/mime@3.0.4:
- resolution: {integrity: sha512-iJt33IQnVRkqeqC7PzBHPTC6fDlRNRW8vjrgqtScAhrmMwe8c4Eo7+fUGTa+XdWrpEgpyKWMYmi2dIwMAYRzPw==}
+ /@types/mime@4.0.0:
+ resolution: {integrity: sha512-5eEkJZ/BLvTE3vXGKkWlyTSUVZuzj23Wj8PoyOq2lt5I3CYbiLBOPb3XmCW6QcuOibIUE6emHXHt9E/F/rCa6w==}
+ deprecated: This is a stub types definition. mime provides its own type definitions, so you do not need this installed.
+ dependencies:
+ mime: 4.0.1
dev: true
/@types/minimatch@5.1.2:
resolution: {integrity: sha512-PDRk21MnK70hja/YF8AHfC7yIsiQHn1rcXx7ijCFBX/k+XQJhQT/gw3xekXKJvx+5SXaMMS8oqQy09Mzvz2TuQ==}
dependencies:
'@types/http-errors': 2.0.4
- '@types/mime': 3.0.4
+ '@types/mime': 4.0.0
'@types/node': 20.12.2
dev: true
hasBin: true
dev: false
+ /mime@4.0.1:
+ resolution: {integrity: sha512-5lZ5tyrIfliMXzFtkYyekWbtRXObT9OWa8IwQ5uxTBDHucNNwniRqo0yInflj+iYi5CBa6qxadGzGarDfuEOxA==}
+ engines: {node: '>=16'}
+ hasBin: true
+ dev: true
+
/minimatch@3.1.2:
resolution: {integrity: sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==}
dependencies:
resolution: {integrity: sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w==}
dev: true
- /@types/mime@3.0.4:
- resolution: {integrity: sha512-iJt33IQnVRkqeqC7PzBHPTC6fDlRNRW8vjrgqtScAhrmMwe8c4Eo7+fUGTa+XdWrpEgpyKWMYmi2dIwMAYRzPw==}
+ /@types/mime@4.0.0:
+ resolution: {integrity: sha512-5eEkJZ/BLvTE3vXGKkWlyTSUVZuzj23Wj8PoyOq2lt5I3CYbiLBOPb3XmCW6QcuOibIUE6emHXHt9E/F/rCa6w==}
+ deprecated: This is a stub types definition. mime provides its own type definitions, so you do not need this installed.
+ dependencies:
+ mime: 4.0.1
dev: true
/@types/node@20.12.2:
resolution: {integrity: sha512-PDRk21MnK70hja/YF8AHfC7yIsiQHn1rcXx7ijCFBX/k+XQJhQT/gw3xekXKJvx+5SXaMMS8oqQy09Mzvz2TuQ==}
dependencies:
'@types/http-errors': 2.0.4
- '@types/mime': 3.0.4
+ '@types/mime': 4.0.0
'@types/node': 20.12.2
dev: true
hasBin: true
dev: false
+ /mime@4.0.1:
+ resolution: {integrity: sha512-5lZ5tyrIfliMXzFtkYyekWbtRXObT9OWa8IwQ5uxTBDHucNNwniRqo0yInflj+iYi5CBa6qxadGzGarDfuEOxA==}
+ engines: {node: '>=16'}
+ hasBin: true
+ dev: true
+
/minimist@1.2.8:
resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==}
dev: true
})
}
+ /**
+ * Starts the minimum number of workers.
+ */
+ private startMinimumNumberOfWorkers (): void {
+ while (
+ this.workerNodes.reduce(
+ (accumulator, workerNode) =>
+ !workerNode.info.dynamic ? accumulator + 1 : accumulator,
+ 0
+ ) < this.minimumNumberOfWorkers
+ ) {
+ this.createAndSetupWorkerNode()
+ }
+ }
+
/** @inheritdoc */
public start (): void {
if (this.started) {
throw new Error('Cannot start a destroying pool')
}
this.starting = true
- while (
- this.workerNodes.reduce(
- (accumulator, workerNode) =>
- !workerNode.info.dynamic ? accumulator + 1 : accumulator,
- 0
- ) < this.minimumNumberOfWorkers
- ) {
- this.createAndSetupWorkerNode()
- }
+ this.startMinimumNumberOfWorkers()
this.starting = false
this.started = true
}
)
workerNode.registerOnceWorkerEventHandler('exit', () => {
this.removeWorkerNode(workerNode)
+ if (this.started && !this.destroying) {
+ this.startMinimumNumberOfWorkers()
+ }
})
const workerNodeKey = this.addWorkerNode(workerNode)
this.afterWorkerNodeSetup(workerNodeKey)
await expect(pool.destroyWorkerNode(workerNodeKey)).resolves.toBeUndefined()
expect(disconnectEvent).toBe(1)
expect(exitEvent).toBe(1)
- expect(pool.workerNodes.length).toBe(numberOfWorkers - 1)
+ // Simulates an illegitimate worker node destroy and the minimum number of worker nodes is guaranteed
+ expect(pool.workerNodes.length).toBe(numberOfWorkers)
await pool.destroy()
})
})
await expect(pool.destroyWorkerNode(workerNodeKey)).resolves.toBeUndefined()
expect(exitEvent).toBe(1)
- expect(pool.workerNodes.length).toBe(numberOfThreads - 1)
+ // Simulates an illegitimate worker node destroy and the minimum number of worker nodes is guaranteed
+ expect(pool.workerNodes.length).toBe(numberOfThreads)
await pool.destroy()
})