diff --git a/powerdns/handlerGetAllDomains.go b/powerdns/handlerGetAllDomains.go index 58b0f55..60e6678 100644 --- a/powerdns/handlerGetAllDomains.go +++ b/powerdns/handlerGetAllDomains.go @@ -3,6 +3,10 @@ package powerdns import "time" func handleGetAllDomains() Response { + + mu.RLock() + defer mu.RUnlock() + currentUnixTimestamp := int(time.Now().Unix()) domains := []DomainInfo{} for domain := range topLevelDomains { diff --git a/powerdns/handlerGetDomainInfo.go b/powerdns/handlerGetDomainInfo.go index 96eb64e..bedc3ca 100644 --- a/powerdns/handlerGetDomainInfo.go +++ b/powerdns/handlerGetDomainInfo.go @@ -3,6 +3,10 @@ package powerdns import "time" func handleGetDomainInfo(params Parameters) Response { + + mu.RLock() + defer mu.RUnlock() + currentUnixTimestamp := int(time.Now().Unix()) for _, config := range powerDNSConfigs { if config.Domain == params.Qname { diff --git a/powerdns/handlerGetDomainKeys.go b/powerdns/handlerGetDomainKeys.go index 889eaaf..562db55 100644 --- a/powerdns/handlerGetDomainKeys.go +++ b/powerdns/handlerGetDomainKeys.go @@ -3,6 +3,7 @@ package powerdns import "strings" func handleGetDomainKeys(params Parameters) Response { + mu.RLock() defer mu.RUnlock() diff --git a/powerdns/handlerLookup.go b/powerdns/handlerLookup.go index 2324eba..f43790d 100644 --- a/powerdns/handlerLookup.go +++ b/powerdns/handlerLookup.go @@ -2,7 +2,7 @@ package powerdns import ( "fmt" - "io/ioutil" + "io" "log" "math" "net" @@ -12,6 +12,10 @@ import ( ) func handleLookup(params Parameters) Response { + + mu.RLock() + defer mu.RUnlock() + domain := strings.ToLower(strings.TrimSuffix(params.Qname, ".")) // log.Printf("Looking up domain: %s, type: %s", domain, params.Qtype) @@ -76,9 +80,6 @@ func handleLookup(params Parameters) Response { } } - mu.RLock() - defer mu.RUnlock() - var closestMember Member minDistance := math.MaxFloat64 @@ -201,7 +202,7 @@ func fetchACMEChallenge(url string) (string, error) { } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return "", fmt.Errorf("failed to read response body: %w", err) }