Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip retry on bad requests #66

Merged
merged 2 commits into from
Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions internal/dependency/kv_exists_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dependency

import (
"fmt"
"strings"

"github.com/hashicorp/hcat/dep"
"github.com/pkg/errors"
Expand Down Expand Up @@ -40,11 +41,15 @@ func (d *KVExistsGetQuery) CanShare() bool {
// String returns the human-friendly version of this dependency.
func (d *KVExistsGetQuery) String() string {
key := d.key
var opts []string
if d.dc != "" {
key = key + "dc=" + d.dc
opts = append(opts, "dc="+d.dc)
}
if d.ns != "" {
key = key + "ns=" + d.ns
opts = append(opts, "ns="+d.ns)
}
if len(opts) > 0 {
key = fmt.Sprintf("%s?%s", key, strings.Join(opts, "&"))
}
return fmt.Sprintf("kv.exists.get(%s)", key)
}
Expand Down
8 changes: 7 additions & 1 deletion view.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ func (v *view) poll(viewCh chan<- *view, errCh chan<- error) {
retries = 0
goto WAIT
case err := <-fetchErrCh:
var skipRetry bool
if strings.Contains(err.Error(), "Unexpected response code: 400") {
// 400 is not useful to retry
skipRetry = true
}

if strings.Contains(err.Error(), "connection refused") {
// This indicates that Consul may have restarted. If Consul
// restarted, the current lastIndex will be stale and cause the
Expand All @@ -194,7 +200,7 @@ func (v *view) poll(viewCh chan<- *view, errCh chan<- error) {
v.dataLock.Unlock()
}

if v.retryFunc != nil {
if v.retryFunc != nil && !skipRetry {
retry, sleep := v.retryFunc(retries)
if retry {
//log.Printf("[WARN] (view) %s (retry attempt %d after %q)",
Expand Down