mirror of
https://github.com/safing/portmaster
synced 2025-09-11 07:24:36 +00:00
Suggest using stale DNS cache when queries are slow
This commit is contained in:
parent
f6d90b008a
commit
89bad684cf
6 changed files with 132 additions and 2 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue