Skip to content

Commit

Permalink
Reduce DNS handler chain lock contention
Browse files Browse the repository at this point in the history
  • Loading branch information
lixmal committed Dec 21, 2024
1 parent 7ee7ada commit c3e4e57
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions client/internal/dns/handler_chain.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dns

import (
"slices"
"strings"
"sync"

Expand Down Expand Up @@ -161,16 +162,19 @@ func (c *HandlerChain) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
log.Tracef("handling DNS request for domain=%s", qname)

c.mu.RLock()
defer c.mu.RUnlock()

log.Tracef("current handlers (%d):", len(c.handlers))
for _, h := range c.handlers {
log.Tracef(" - pattern: domain=%s original: domain=%s wildcard=%v priority=%d",
h.Pattern, h.OrigPattern, h.IsWildcard, h.Priority)
handlers := slices.Clone(c.handlers)
c.mu.RUnlock()

if log.IsLevelEnabled(log.TraceLevel) {
log.Tracef("current handlers (%d):", len(handlers))
for _, h := range handlers {
log.Tracef(" - pattern: domain=%s original: domain=%s wildcard=%v priority=%d",
h.Pattern, h.OrigPattern, h.IsWildcard, h.Priority)
}
}

// Try handlers in priority order
for _, entry := range c.handlers {
for _, entry := range handlers {
var matched bool
switch {
case entry.Pattern == ".":
Expand Down

0 comments on commit c3e4e57

Please sign in to comment.