diff options
Diffstat (limited to 'internal')
-rw-r--r-- | internal/qna/qna.go | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/internal/qna/qna.go b/internal/qna/qna.go index 809df15..aa27d07 100644 --- a/internal/qna/qna.go +++ b/internal/qna/qna.go @@ -1,6 +1,8 @@ package qna import ( + "context" + "errors" "fmt" "net" "net/url" @@ -38,6 +40,9 @@ type Progress struct { NumOK int // got response NumOnion int // found onion in response + // More details about deadline errors while sending request + NumDeadline int + // More details about DNS errors while sending request NumDNSNotFound int NumDNSTimeout int @@ -48,6 +53,7 @@ func (p Progress) String() string { str := fmt.Sprintf(" Processed: %d\n", p.NumAnswer()) str += fmt.Sprintf(" Success: %d (Onion-Location:%d)\n", p.NumOK, p.NumOnion) str += fmt.Sprintf(" Failure: %d (Req:%d Do:%d)\n", p.NumError(), p.NumReqErr, p.NumDoErr) + str += fmt.Sprintf(" CTX: %d (Deadline exceeded)\n", p.NumDeadline) str += fmt.Sprintf(" DNS: %d (NotFound:%d Timeout:%d Other:%d)", p.NumDNSErr(), p.NumDNSNotFound, p.NumDNSTimeout, p.NumDNSOther) return str @@ -72,17 +78,17 @@ func (p *Progress) AddAnswer(a Answer) { } if a.DoErr != nil { p.NumDoErr += 1 - err := dnsError(a.DoErr) - if err == nil { - return + if isDeadlineError(a.DoErr) { + p.NumDeadline += 1 } - - if err.IsTimeout { - p.NumDNSTimeout += 1 - } else if err.IsNotFound { - p.NumDNSNotFound += 1 - } else { - p.NumDNSOther += 1 + if err := dnsError(a.DoErr); err != nil { + if err.IsTimeout { + p.NumDNSTimeout += 1 + } else if err.IsNotFound { + p.NumDNSNotFound += 1 + } else { + p.NumDNSOther += 1 + } } return } @@ -117,3 +123,8 @@ func dnsError(err error) *net.DNSError { return dnsErr } + +func isDeadlineError(err error) bool { + urlErr, ok := err.(*url.Error) + return ok && errors.Is(urlErr.Err, context.DeadlineExceeded) +} |