mirror of
https://github.com/coredns/coredns.git
synced 2025-10-26 15:54:16 -04:00
fix(multisocket): cap num sockets to prevent OOM (#7615)
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user