1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-01-14 02:33:03 +02:00

fix ewma panic (#2480)

* fix ewma panic
This commit is contained in:
Tony Chen 2022-10-28 20:22:14 +08:00 committed by GitHub
parent 3c65f16737
commit f0878b0a78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View File

@ -161,7 +161,7 @@ func (n *Node) Pick() selector.DoneFunc {
}
var netErr net.Error
if errors.Is(context.DeadlineExceeded, di.Err) || errors.Is(context.Canceled, di.Err) ||
errors.IsServiceUnavailable(di.Err) || errors.IsGatewayTimeout(di.Err) || errors.As(di.Err, netErr) {
errors.IsServiceUnavailable(di.Err) || errors.IsGatewayTimeout(di.Err) || errors.As(di.Err, &netErr) {
success = 0
}
}

View File

@ -2,6 +2,7 @@ package ewma
import (
"context"
"net"
"reflect"
"testing"
"time"
@ -100,11 +101,15 @@ func TestDirectErrorHandler(t *testing.T) {
Endpoints: []string{"http://127.0.0.1:9090"},
Metadata: map[string]string{"weight": "10"},
}))
errs := []error{
context.DeadlineExceeded,
context.Canceled,
net.ErrClosed,
}
for i := 0; i < 5; i++ {
var err error
if i != 0 {
err = context.DeadlineExceeded
err = errs[i%len(errs)]
}
done := wn.Pick()
if done == nil {