Skip to content

Commit

Permalink
Merge pull request #38 from kumparan/misc/filter-circuit-breaker-error
Browse files Browse the repository at this point in the history
misc: circuit breaker can only open by certain error codes
  • Loading branch information
atjhoendz authored Sep 26, 2024
2 parents 7385ad1 + b42844d commit 868ae41
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# go-connect

<a name="v1.18.2"></a>
## [v1.18.2] - 2024-09-26
### Other Improvements
- circuit breaker can only open by certain error codes


<a name="v1.18.1"></a>
## [v1.18.1] - 2024-07-11
### Other Improvements
- fix vulnerability libraries and fix lint
- fix vulnerabilities library and fix lint ([#37](https://github.com/kumparan/go-connect/issues/37))


<a name="v1.18.0"></a>
Expand Down Expand Up @@ -231,7 +237,8 @@
- init go-connect with http and redis connector ([#1](https://github.com/kumparan/go-connect/issues/1))


[Unreleased]: https://github.com/kumparan/go-connect/compare/v1.18.1...HEAD
[Unreleased]: https://github.com/kumparan/go-connect/compare/v1.18.2...HEAD
[v1.18.2]: https://github.com/kumparan/go-connect/compare/v1.18.1...v1.18.2
[v1.18.1]: https://github.com/kumparan/go-connect/compare/v1.18.0...v1.18.1
[v1.18.0]: https://github.com/kumparan/go-connect/compare/v1.17.0...v1.18.0
[v1.17.0]: https://github.com/kumparan/go-connect/compare/v1.16.1...v1.17.0
Expand Down
17 changes: 15 additions & 2 deletions grpc_connect_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,31 @@ func UnaryClientInterceptor(opts *GRPCUnaryInterceptorOptions) grpc.UnaryClientI

if o.UseCircuitBreaker {
success := make(chan bool, 1)
ignoredError := make(chan error, 1)
errC := hystrix.GoC(ctx, method, func(ctx context.Context) error {
err := o.retryableInvoke(ctx, method, req, reply, cc, invoker, opts...)
if err == nil {

switch status.Code(err) {
case codes.OK:
success <- true
return nil
case codes.Internal, // circuit breaker can only open by these error codes
codes.Unknown,
codes.Unavailable,
codes.DeadlineExceeded:
return err
default:
ignoredError <- err
return nil
}
return err
}, nil)

select {
case out := <-success:
logrus.Debugf("success %v", out)
return nil
case err := <-ignoredError:
return err
case err := <-errC:
logrus.Warnf("failed %s", err)
return err
Expand Down

0 comments on commit 868ae41

Please sign in to comment.