fix ewma panic (#2480)

* fix ewma panic
pull/2483/head
Tony Chen 2 years ago committed by GitHub
parent 3c65f16737
commit f0878b0a78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      selector/node/ewma/node.go
  2. 9
      selector/node/ewma/node_test.go

@ -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
}
}

@ -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 {

Loading…
Cancel
Save