commit 8fb2e220d02307c14107f0a1af3668bb06ec10c5
parent cd7b62d3b58d546fdbb57af7ca3b533724658597
Author: Sebastien Couture <scouture@bandwidth.com>
Date: Fri, 23 Sep 2022 13:48:48 -0400
Allow setting a Timeout parameter through a net.Dialer.
This takes a value (in ms) specifying how long we are willing to wait for
an answer to our DNS query.
Diffstat:
1 file changed, 7 insertions(+), 0 deletions(-)
diff --git a/rrda.go b/rrda.go
@@ -27,8 +27,11 @@ import (
"net/http/fcgi"
"os"
"strings"
+ "time"
)
+var timeout_ms int
+
type Error struct {
Code int `json:"code"`
Message string `json:"message"`
@@ -107,6 +110,9 @@ func resolve(w http.ResponseWriter, r *http.Request, server string, domain strin
w.Header().Set("Access-Control-Allow-Origin", "*")
c := new(dns.Client)
+ c.Dialer = &net.Dialer{
+ Timeout: time.Duration(timeout_ms) * time.Millisecond,
+ }
Redo:
if in, _, err := c.Exchange(m, server); err == nil { // Second return value is RTT, not used for now
@@ -167,6 +173,7 @@ func main() {
fastcgi := flag.Bool("fastcgi", false, "Enable FastCGI mode")
host := flag.String("host", "127.0.0.1", "Set the server host")
port := flag.String("port", "8080", "Set the server port")
+ flag.IntVar(&timeout_ms, "timeout", 2000, "Set the query timeout in ms")
version := flag.Bool("version", false, "Display version")
mode := "HTTP"