Skip to content

Commit cbb265d

Browse files
committed
fix(config): reject unrepresentable derived dynamic-pool maximum
A minimum at the safe-integer boundary made the derived maximum unrepresentable (2^53, outside safe integers); it sailed past schema parsing and failed at boot with an unstructured RangeError from poolifier. The resolver now rejects configuredMin >= Number.MAX_SAFE_INTEGER with a structured ConfigurationValidationError (phase: 'schema', path worker.poolMinSize). Tests: rename new block to the 'should ...' convention; cover the CPU-floor/cap branches (min below/above the defaults), max-only 2 -> min 1, omitted processType, and the safe-integer guard. Fixes #2207
1 parent 5adcf81 commit cbb265d

3 files changed

Lines changed: 90 additions & 12 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ The `<assets-dir>/configurations` subdirectory is created by the runtime when pe
204204

205205
- **workerSet** ignores both bounds.
206206
- **fixedPool** consumes only `poolMaxSize`; `poolMinSize` is ignored.
207-
- **dynamicPool** requires both bounds with `poolMinSize < poolMaxSize`. When a bound is omitted, it is derived at validation time from the configured sibling bound and the CPU-based default (minimum derived from the maximum, maximum derived from the minimum, capped/floored at the CPU defaults). A maximum of 1 cannot be worked around (the minimum would be 0), and an explicit pair with `poolMinSize >= poolMaxSize` is rejected with a structured configuration error.
207+
- **dynamicPool** requires both bounds with `poolMinSize < poolMaxSize`. When a bound is omitted, it is derived at validation time from the configured sibling bound and the CPU-based default (minimum derived from the maximum, maximum derived from the minimum, capped/floored at the CPU defaults). A maximum of 1 cannot be worked around (the minimum would be 0), a minimum above the safe-integer range cannot be raised to a valid maximum, and an explicit pair with `poolMinSize >= poolMaxSize` is rejected with a structured configuration error.
208208

209209
### Charging station template configuration
210210

‎src/utils/ConfigurationValidation.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ import { assertIsJsonObject, clone, isEmpty, isNotEmptyArray } from './Utils.js'
3434
* - Both explicit: they must be strictly ordered, otherwise the configuration
3535
* is rejected with structured field errors.
3636
* - Only `poolMinSize`: the maximum is derived from the minimum, using the
37-
* CPU-based default as a floor.
37+
* CPU-based default as a floor. A minimum for which no larger safe integer
38+
* exists is rejected (no drawable maximum would remain).
3839
* - Only `poolMaxSize`: the minimum is derived from the maximum, using the
3940
* CPU-based default as a cap. A maximum of 1 cannot be worked around
4041
* (the minimum would be 0) so the configuration is rejected.
@@ -73,6 +74,17 @@ const resolveDynamicPoolBounds = (
7374
return worker
7475
}
7576
if (configuredMin != null) {
77+
if (configuredMin >= Number.MAX_SAFE_INTEGER) {
78+
throw new ConfigurationValidationError(
79+
[
80+
{
81+
message: `dynamic pool minimum of ${configuredMin.toString()} cannot be raised to a valid maximum (the next safe integer is non-representable)`,
82+
path: 'worker.poolMinSize',
83+
},
84+
],
85+
{ filePath, migratedFrom, phase: 'schema' }
86+
)
87+
}
7688
return {
7789
...worker,
7890
poolMaxSize: Math.max(DEFAULT_POOL_MAX_SIZE, configuredMin + 1),

‎tests/utils/ConfigurationValidation.test.ts‎

Lines changed: 76 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ await describe('ConfigurationValidation', async () => {
549549
})
550550
})
551551
await describe('dynamic pool bounds resolution', async () => {
552-
await it('derives the maximum from an explicit minimum', () => {
552+
await it('should derive the maximum from an explicit minimum', () => {
553553
const parsed = buildMinimalConfiguration({
554554
worker: { poolMinSize: 4, processType: 'dynamicPool' },
555555
})
@@ -561,7 +561,7 @@ await describe('ConfigurationValidation', async () => {
561561
assert.strictEqual(worker.poolMaxSize, Math.max(DEFAULT_POOL_MAX_SIZE, 5))
562562
})
563563

564-
await it('derives the minimum from an explicit maximum', () => {
564+
await it('should derive the minimum from an explicit maximum', () => {
565565
const parsed = buildMinimalConfiguration({
566566
worker: { poolMaxSize: 8, processType: 'dynamicPool' },
567567
})
@@ -573,7 +573,7 @@ await describe('ConfigurationValidation', async () => {
573573
assert.strictEqual(worker.poolMaxSize, 8)
574574
})
575575

576-
await it('rejects a maximum of 1 without an explicit minimum', () => {
576+
await it('should reject a maximum of 1 without an explicit minimum', () => {
577577
const parsed = buildMinimalConfiguration({
578578
worker: { poolMaxSize: 1, processType: 'dynamicPool' },
579579
})
@@ -593,7 +593,7 @@ await describe('ConfigurationValidation', async () => {
593593
)
594594
})
595595

596-
await it('rejects an explicit pair whose maximum is not greater than its minimum', () => {
596+
await it('should reject an explicit pair whose maximum is not greater than its minimum', () => {
597597
const parsed = buildMinimalConfiguration({
598598
worker: { poolMaxSize: 4, poolMinSize: 4, processType: 'dynamicPool' },
599599
})
@@ -612,7 +612,7 @@ await describe('ConfigurationValidation', async () => {
612612
)
613613
})
614614

615-
await it('rejects an explicit pair whose maximum is below its minimum', () => {
615+
await it('should reject an explicit pair whose maximum is below its minimum', () => {
616616
const parsed = buildMinimalConfiguration({
617617
worker: { poolMaxSize: 3, poolMinSize: 5, processType: 'dynamicPool' },
618618
})
@@ -626,7 +626,7 @@ await describe('ConfigurationValidation', async () => {
626626
)
627627
})
628628

629-
await it('keeps an explicit ordered pair unchanged', () => {
629+
await it('should keep an explicit ordered pair unchanged', () => {
630630
const parsed = buildMinimalConfiguration({
631631
worker: { poolMaxSize: 5, poolMinSize: 2, processType: 'dynamicPool' },
632632
})
@@ -637,7 +637,7 @@ await describe('ConfigurationValidation', async () => {
637637
assert.strictEqual(worker.poolMaxSize, 5)
638638
})
639639

640-
await it('leaves omitted bounds unchanged for a dynamic pool (defaults apply later)', () => {
640+
await it('should leave omitted bounds unchanged for a dynamic pool (defaults apply later)', () => {
641641
const parsed = buildMinimalConfiguration({
642642
worker: { processType: 'dynamicPool' },
643643
})
@@ -649,7 +649,7 @@ await describe('ConfigurationValidation', async () => {
649649
assert.strictEqual(worker.poolMaxSize, undefined)
650650
})
651651

652-
await it('ignores bounds in fixed-pool configurations (only the maximum is used)', () => {
652+
await it('should ignore bounds in fixed-pool configurations (only the maximum is used)', () => {
653653
const parsed = buildMinimalConfiguration({
654654
worker: { poolMaxSize: 2, poolMinSize: 3, processType: 'fixedPool' },
655655
})
@@ -660,7 +660,7 @@ await describe('ConfigurationValidation', async () => {
660660
assert.strictEqual(worker.poolMaxSize, 2)
661661
})
662662

663-
await it('ignores bounds in workerSet configurations', () => {
663+
await it('should ignore bounds in workerSet configurations', () => {
664664
const parsed = buildMinimalConfiguration({
665665
worker: { poolMaxSize: 2, poolMinSize: 4, processType: 'workerSet' },
666666
})
@@ -671,7 +671,7 @@ await describe('ConfigurationValidation', async () => {
671671
assert.strictEqual(worker.poolMaxSize, 2)
672672
})
673673

674-
await it('derives canonical bounds from legacy alias keys', () => {
674+
await it('should derive canonical bounds from legacy alias keys', () => {
675675
const parsed = buildMinimalConfiguration({
676676
worker: { processType: 'dynamicPool' },
677677
workerPoolMinSize: 3,
@@ -683,5 +683,71 @@ await describe('ConfigurationValidation', async () => {
683683
assert.strictEqual(worker.poolMinSize, 3)
684684
assert.strictEqual(worker.poolMaxSize, Math.max(DEFAULT_POOL_MAX_SIZE, 4))
685685
})
686+
687+
await it('should floor the derived maximum at the CPU default for a minimum below it', () => {
688+
const parsed = buildMinimalConfiguration({
689+
worker: { poolMinSize: 1, processType: 'dynamicPool' },
690+
})
691+
const result = validateConfiguration(parsed, 'bounds-min-1.json')
692+
const worker = result.worker
693+
assert.ok(worker)
694+
assert.strictEqual(worker.poolMinSize, 1)
695+
assert.strictEqual(worker.poolMaxSize, Math.max(DEFAULT_POOL_MAX_SIZE, 2))
696+
})
697+
698+
await it('should derive a minimum of 1 from an explicit maximum of 2', () => {
699+
const parsed = buildMinimalConfiguration({
700+
worker: { poolMaxSize: 2, processType: 'dynamicPool' },
701+
})
702+
const result = validateConfiguration(parsed, 'bounds-max-2.json')
703+
const worker = result.worker
704+
assert.ok(worker)
705+
assert.strictEqual(worker.poolMinSize, 1)
706+
assert.strictEqual(worker.poolMaxSize, 2)
707+
})
708+
709+
await it('should reject a minimum for which no larger safe integer exists', () => {
710+
const parsed = buildMinimalConfiguration({
711+
worker: { poolMinSize: Number.MAX_SAFE_INTEGER, processType: 'dynamicPool' },
712+
})
713+
assert.throws(
714+
() => validateConfiguration(parsed, 'bounds-max-safe-integer.json'),
715+
(error: unknown) => {
716+
assert.ok(error instanceof ConfigurationValidationError)
717+
assert.strictEqual(error.phase, 'schema')
718+
assert.ok(
719+
error.fieldErrors.some(
720+
e => e.path === 'worker.poolMinSize' && e.message.includes('non-representable')
721+
),
722+
`Expected a poolMinSize field error, got ${JSON.stringify(error.fieldErrors)}`
723+
)
724+
return true
725+
}
726+
)
727+
})
728+
729+
await it('should derive the maximum from a minimum above the CPU default', () => {
730+
const min = DEFAULT_POOL_MAX_SIZE + 1
731+
const parsed = buildMinimalConfiguration({
732+
worker: { poolMinSize: min, processType: 'dynamicPool' },
733+
})
734+
const result = validateConfiguration(parsed, 'bounds-min-above-default.json')
735+
const worker = result.worker
736+
assert.ok(worker)
737+
assert.strictEqual(worker.poolMinSize, min)
738+
assert.strictEqual(worker.poolMaxSize, min + 1)
739+
})
740+
741+
await it('should leave bounds unchanged when processType is omitted (workerSet default)', () => {
742+
const parsed = buildMinimalConfiguration({
743+
worker: { poolMaxSize: 9, poolMinSize: 4 },
744+
})
745+
const result = validateConfiguration(parsed, 'bounds-omitted-type.json')
746+
const worker = result.worker
747+
assert.ok(worker)
748+
assert.strictEqual(worker.processType, undefined)
749+
assert.strictEqual(worker.poolMinSize, 4)
750+
assert.strictEqual(worker.poolMaxSize, 9)
751+
})
686752
})
687753
})

0 commit comments

Comments
 (0)