Skip to content

Commit 6fa0e25

Browse files
authored
Don't allow max-connections to be scaled to a point where PG can't boot (#187)
1 parent d8c88b2 commit 6fa0e25

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

internal/flypg/pg.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,25 @@ func (c *PGConfig) validateCompatibility(requested ConfigMap) (ConfigMap, error)
397397
}
398398
}
399399

400+
// Max-connections
401+
if v, ok := requested["max_connections"]; ok {
402+
{
403+
const minConnections = 10
404+
405+
val := v.(string)
406+
407+
// Convert string to int
408+
maxConnections, err := strconv.ParseInt(val, 10, 64)
409+
if err != nil {
410+
return requested, fmt.Errorf("failed to parse max-connections: %s", err)
411+
}
412+
413+
if maxConnections < minConnections {
414+
return requested, fmt.Errorf("max_connections cannot be configured below %d", minConnections)
415+
}
416+
}
417+
}
418+
400419
return requested, nil
401420
}
402421

internal/flypg/pg_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,21 @@ func TestValidateCompatibility(t *testing.T) {
453453
}
454454
})
455455

456+
t.Run("maxConnections", func(t *testing.T) {
457+
valid := ConfigMap{
458+
"max_connections": "14",
459+
}
460+
if _, err := pgConf.validateCompatibility(valid); err != nil {
461+
t.Fatal(err)
462+
}
463+
464+
invalid := ConfigMap{
465+
"max_connections": "4",
466+
}
467+
if _, err := pgConf.validateCompatibility(invalid); err == nil {
468+
t.Fatal(err)
469+
}
470+
})
456471
}
457472

458473
func stubPGConfigFile() error {

0 commit comments

Comments
 (0)