From b0f99e72bb8316618ffa5377925aafe2bc063b60 Mon Sep 17 00:00:00 2001 From: David Fifield Date: Thu, 16 Apr 2020 23:54:27 -0600 Subject: [PATCH] Handle other unknown response status codes the same as 429. --- dnstt-client/http.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/dnstt-client/http.go b/dnstt-client/http.go index bd54018..7fc651a 100644 --- a/dnstt-client/http.go +++ b/dnstt-client/http.go @@ -84,7 +84,10 @@ func (c *HTTPPacketConn) send(p []byte) error { } // Ignore err != nil; don't report an error if we at least // managed to send. - case http.StatusTooManyRequests: + default: + // We primarily are thinking of 429 Too Many Requests here, but + // any other unexpected response codes will also cause us to + // rate-limit ourself and emit a log message. // https://developers.google.com/speed/public-dns/docs/doh/#errors now := time.Now() var retryAfter time.Time @@ -97,7 +100,7 @@ func (c *HTTPPacketConn) send(p []byte) error { } if retryAfter.IsZero() { // Supply a default. - retryAfter = now.Add(60 * time.Second) + retryAfter = now.Add(10 * time.Second) } c.notBeforeLock.Lock() if retryAfter.After(now) && retryAfter.After(c.notBefore) { @@ -105,8 +108,6 @@ func (c *HTTPPacketConn) send(p []byte) error { c.notBefore = retryAfter } c.notBeforeLock.Unlock() - default: - return fmt.Errorf("unknown HTTP response status %+q", resp.Status) } return nil