Skip to content

Commit

Permalink
fix: respect ipv4/6 disable settings for DNS too
Browse files Browse the repository at this point in the history
  • Loading branch information
CorentinB committed Nov 22, 2024
1 parent 02242de commit 207ca8b
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package warc

import (
"fmt"
"log/slog"
"net"
"sync"
"time"
Expand Down Expand Up @@ -51,24 +50,27 @@ func (d *customDialer) archiveDNS(address string) (resolvedIP net.IP, err error)
fallbackServers := min(maxFallbackDNSServers, len(d.DNSConfig.Servers)-1)

for DNSServer := 0; DNSServer <= fallbackServers; DNSServer++ {
wg.Add(2)

go func() {
defer wg.Done()
ipv4, errA = d.lookupIP(address, dns.TypeA, DNSServer)
}()
if !d.disableIPv4 {
wg.Add(1)
go func() {
defer wg.Done()
ipv4, errA = d.lookupIP(address, dns.TypeA, DNSServer)
}()
}

go func() {
defer wg.Done()
ipv6, errAAAA = d.lookupIP(address, dns.TypeAAAA, DNSServer)
}()
if !d.disableIPv6 {
wg.Add(1)
go func() {
defer wg.Done()
ipv6, errAAAA = d.lookupIP(address, dns.TypeAAAA, DNSServer)
}()
}

wg.Wait()

if errA == nil || errAAAA == nil {
break
}
slog.Warn("Failed to resolve DNS", "DNS", d.DNSConfig.Servers[DNSServer], "address", address, "errA", errA, "errAAAA", errAAAA)
}
if errA != nil && errAAAA != nil {
return nil, fmt.Errorf("failed to resolve DNS: A error: %v, AAAA error: %v", errA, errAAAA)
Expand Down

0 comments on commit 207ca8b

Please sign in to comment.