forked from coredns/coredns
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plugin/timeouts - Allow ability to configure listening server timeouts (
- Loading branch information
Showing
14 changed files
with
369 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# only add build artifacts concerning coredns - no editor related files | ||
coredns | ||
coredns.exe | ||
Corefile | ||
build/ | ||
release/ | ||
vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ var Directives = []string{ | |
"geoip", | ||
"cancel", | ||
"tls", | ||
"timeouts", | ||
"reload", | ||
"nsid", | ||
"bufsize", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package durations | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
// NewDurationFromArg returns a time.Duration from a configuration argument | ||
// (string) which has come from the Corefile. The argument has some basic | ||
// validation applied before returning a time.Duration. If the argument has no | ||
// time unit specified and is numeric the argument will be treated as seconds | ||
// rather than GO's default of nanoseconds. | ||
func NewDurationFromArg(arg string) (time.Duration, error) { | ||
_, err := strconv.Atoi(arg) | ||
if err == nil { | ||
arg = arg + "s" | ||
} | ||
|
||
d, err := time.ParseDuration(arg) | ||
if err != nil { | ||
return 0, fmt.Errorf("failed to parse duration '%s'", arg) | ||
} | ||
|
||
return d, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package durations | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestNewDurationFromArg(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
arg string | ||
wantErr bool | ||
want time.Duration | ||
}{ | ||
{ | ||
name: "valid GO duration - seconds", | ||
arg: "30s", | ||
want: 30 * time.Second, | ||
}, | ||
{ | ||
name: "valid GO duration - minutes", | ||
arg: "2m", | ||
want: 2 * time.Minute, | ||
}, | ||
{ | ||
name: "number - fallback to seconds", | ||
arg: "30", | ||
want: 30 * time.Second, | ||
}, | ||
{ | ||
name: "invalid duration", | ||
arg: "twenty seconds", | ||
wantErr: true, | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
actual, err := NewDurationFromArg(test.arg) | ||
if test.wantErr && err == nil { | ||
t.Error("error was expected") | ||
} | ||
if !test.wantErr && err != nil { | ||
t.Error("error was not expected") | ||
} | ||
|
||
if test.want != actual { | ||
t.Errorf("expected '%v' got '%v'", test.want, actual) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# timeouts | ||
|
||
## Name | ||
|
||
*timeouts* - allows you to configure the server read, write and idle timeouts for the TCP, TLS and DoH servers. | ||
|
||
## Description | ||
|
||
CoreDNS is configured with sensible timeouts for server connections by default. | ||
However in some cases for example where CoreDNS is serving over a slow mobile | ||
data connection the default timeouts are not optimal. | ||
|
||
Additionally some routers hold open connections when using DNS over TLS or DNS | ||
over HTTPS. Allowing a longer idle timeout helps performance and reduces issues | ||
with such routers. | ||
|
||
The *timeouts* "plugin" allows you to configure CoreDNS server read, write and | ||
idle timeouts. | ||
|
||
## Syntax | ||
|
||
~~~ txt | ||
timeouts { | ||
read DURATION | ||
write DURATION | ||
idle DURATION | ||
} | ||
~~~ | ||
|
||
For any timeouts that are not provided, default values are used which may vary | ||
depending on the server type. At least one timeout must be specified otherwise | ||
the entire timeouts block should be omitted. | ||
|
||
## Examples | ||
|
||
Start a DNS-over-TLS server that picks up incoming DNS-over-TLS queries on port | ||
5553 and uses the nameservers defined in `/etc/resolv.conf` to resolve the | ||
query. This proxy path uses plain old DNS. A 10 second read timeout, 20 | ||
second write timeout and a 60 second idle timeout have been configured. | ||
|
||
~~~ | ||
tls://.:5553 { | ||
tls cert.pem key.pem ca.pem | ||
timeouts { | ||
read 10s | ||
write 20s | ||
idle 60s | ||
} | ||
forward . /etc/resolv.conf | ||
} | ||
~~~ | ||
|
||
Start a DNS-over-HTTPS server that is similar to the previous example. Only the | ||
read timeout has been configured for 1 minute. | ||
|
||
~~~ | ||
https://. { | ||
tls cert.pem key.pem ca.pem | ||
timeouts { | ||
read 1m | ||
} | ||
forward . /etc/resolv.conf | ||
} | ||
~~~ | ||
|
||
Start a standard TCP/UDP server on port 1053. A read and write timeout has been | ||
configured. The timeouts are only applied to the TCP side of the server. | ||
~~~ | ||
.:1053 { | ||
timeouts { | ||
read 15s | ||
write 30s | ||
} | ||
forward . /etc/resolv.conf | ||
} | ||
~~~ |
Oops, something went wrong.