Suggest using stale DNS cache when queries are slow

This commit is contained in:
Daniel 2023-04-24 13:13:24 +02:00
parent f6d90b008a
commit 89bad684cf
6 changed files with 132 additions and 2 deletions

View file

@ -14,6 +14,7 @@ import (
"github.com/miekg/dns"
"github.com/safing/portbase/log"
"github.com/safing/portmaster/netenv"
)
// HTTPSResolver is a resolver using just a single tcp connection with pipelining.
@ -56,6 +57,8 @@ func NewHTTPSResolver(resolver *Resolver) *HTTPSResolver {
// Query executes the given query against the resolver.
func (hr *HTTPSResolver) Query(ctx context.Context, q *Query) (*RRCache, error) {
queryStarted := time.Now()
dnsQuery := new(dns.Msg)
dnsQuery.SetQuestion(q.FQDN, uint16(q.QType))
@ -88,6 +91,9 @@ func (hr *HTTPSResolver) Query(ctx context.Context, q *Query) (*RRCache, error)
resp, err := hr.client.Do(request)
if err != nil {
// Hint network environment at failed connection.
netenv.ReportFailedConnection()
return nil, err
}
defer func() {
@ -111,6 +117,12 @@ func (hr *HTTPSResolver) Query(ctx context.Context, q *Query) (*RRCache, error)
return nil, err
}
// Hint network environment at successful connection.
netenv.ReportSuccessfulConnection()
// Report request duration for metrics.
reportRequestDuration(queryStarted, hr.resolver)
newRecord := &RRCache{
Domain: q.FQDN,
Question: q.QType,