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

Allow only system failures to trigger circuit breaker #667

Merged
merged 4 commits into from Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 20 additions & 4 deletions codegen/template_bundle/template_files.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions codegen/templates/http_client.tmpl
Expand Up @@ -238,10 +238,18 @@ func (c *{{$clientName}}) {{$methodName}}(
if (c.circuitBreakerDisabled) {
res, err = req.Do()
} else {
var realErr error
err = hystrix.DoC(ctx, "{{$clientID}}", func(ctx context.Context) error {
res, err = req.Do()
return err
res, realErr = req.Do()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would choose variable name as clientErr rather than realErr. real vs unreal it looks like from variable name currently

if res.StatusCode < 500 {
argouber marked this conversation as resolved.
Show resolved Hide resolved
argouber marked this conversation as resolved.
Show resolved Hide resolved
return nil
}
return realErr
}, nil)
if err == nil {
// Bad request or equivalent error, bubble it up
err = realErr
}
}
if err != nil {
return {{if eq .ResponseType ""}}nil, err{{else}}defaultRes, nil, err{{end}}
Expand Down
8 changes: 8 additions & 0 deletions codegen/templates/tchannel_client.tmpl
Expand Up @@ -264,12 +264,20 @@ type {{$clientName}} struct {
ctx, "{{$svc.Name}}", "{{.Name}}", reqHeaders, args, &result,
)
} else {
var realErr error
err = hystrix.DoC(ctx, "{{$clientID}}", func(ctx context.Context) error {
success, respHeaders, err = c.client.Call(
argouber marked this conversation as resolved.
Show resolved Hide resolved
ctx, "{{$svc.Name}}", "{{.Name}}", reqHeaders, args, &result,
)
if _, isSysErr := err.(tchannel.SystemError); !isSysErr {
return nil
}
return err
}, nil)
if err == nil {
// Bad request or equivalent error, bubble it up
err = realErr
}
}


Expand Down