fix(multisocket): cap num sockets to prevent OOM (#7615)

This commit is contained in:
Ville Vesilehto
2025-10-14 17:31:57 +03:00
committed by GitHub
parent 89bf0a2cc2
commit f085ed0e6d
3 changed files with 7 additions and 1 deletions

View File

@@ -19,7 +19,7 @@ large number of CPU cores.
multisocket [NUM_SOCKETS]
~~~
* **NUM_SOCKETS** - the number of servers that will listen on one port. Default value is equal to GOMAXPROCS.
* **NUM_SOCKETS** - the number of servers that will listen on one port. Default value is equal to GOMAXPROCS. Maximum value is 1024.
## Examples

View File

@@ -11,6 +11,7 @@ import (
)
const pluginName = "multisocket"
const maxNumSockets = 1024
func init() { plugin.Register(pluginName, setup) }
@@ -45,6 +46,9 @@ func parseNumSockets(c *caddy.Controller) error {
if numSockets < 1 {
return fmt.Errorf("num sockets can not be zero or negative: %d", numSockets)
}
if numSockets > maxNumSockets {
return fmt.Errorf("num sockets exceeds maximum (%d): %d", maxNumSockets, numSockets)
}
config.NumSockets = numSockets
return nil

View File

@@ -19,10 +19,12 @@ func TestMultisocket(t *testing.T) {
// positive
{`multisocket`, false, runtime.GOMAXPROCS(0), ""},
{`multisocket 2`, false, 2, ""},
{`multisocket 1024`, false, 1024, ""},
{` multisocket 1`, false, 1, ""},
{`multisocket text`, true, 0, "invalid num sockets"},
{`multisocket 0`, true, 0, "num sockets can not be zero or negative"},
{`multisocket -1`, true, 0, "num sockets can not be zero or negative"},
{`multisocket 1025`, true, 0, "num sockets exceeds maximum"},
{`multisocket 2 2`, true, 0, "Wrong argument count or unexpected line ending after '2'"},
{`multisocket 2 {
block