Skip to content

Commit

Permalink
upstream: fix net, imp doc
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Dec 28, 2023
1 parent 648565d commit 6643fc0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion upstream/doh.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (p *dnsOverHTTPS) exchangeHTTPS(client *http.Client, req *dns.Msg) (resp *d
}

logBegin(p.addrRedacted, n, req)
defer func() { logFinish(p.addrRedacted, networkTCP, err) }()
defer func() { logFinish(p.addrRedacted, n, err) }()

return p.exchangeHTTPSClient(client, req)
}
Expand Down
18 changes: 13 additions & 5 deletions upstream/upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net"
"net/netip"
"net/url"
"os"
"strconv"
"strings"
"sync/atomic"
Expand Down Expand Up @@ -305,14 +306,21 @@ func logFinish(addr string, n network, err error) {
}

// isTimeout returns true if err is a timeout error.
//
// TODO(e.burkov): Move to golibs.
func isTimeout(err error) (ok bool) {
if errors.Is(err, context.DeadlineExceeded) {
var netErr net.Error
switch {
case
errors.Is(err, context.Canceled),
errors.Is(err, context.DeadlineExceeded),
errors.Is(err, os.ErrDeadlineExceeded):
return true
case errors.As(err, &netErr):
return netErr.Timeout()
default:
return false
}

var netErr net.Error

return errors.As(err, &netErr) && netErr.Timeout()
}

// DialerInitializer returns the handler that it creates. All the subsequent
Expand Down

0 comments on commit 6643fc0

Please sign in to comment.