-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
fix(selector/ewma): do not penalise nodes on context.Canceled (fixes #3834) #3836
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -85,6 +85,61 @@ func TestDirectError(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| // TestCanceledDoesNotDegradeNode verifies that context.Canceled does not | ||
| // lower a node's health score. Canceled means the caller gave up — it is | ||
| // not evidence of backend failure. context.DeadlineExceeded (backend too | ||
| // slow) should still degrade the node as before. | ||
| func TestCanceledDoesNotDegradeNode(t *testing.T) { | ||
| newNode := func() selector.WeightedNode { | ||
| return (&Builder{}).Build(selector.NewNode( | ||
| "http", | ||
| "127.0.0.1:9090", | ||
| ®istry.ServiceInstance{ | ||
| ID: "127.0.0.1:9090", | ||
| Name: "helloworld", | ||
| Version: "v1.0.0", | ||
| Endpoints: []string{"http://127.0.0.1:9090"}, | ||
| Metadata: map[string]string{"weight": "10"}, | ||
| })) | ||
| } | ||
|
|
||
| // --- context.Canceled must NOT degrade health --- | ||
| wn := newNode() | ||
| // One successful pick to initialise EWMA state. | ||
| done := wn.Pick() | ||
| time.Sleep(time.Millisecond * 20) | ||
| done(context.Background(), selector.DoneInfo{}) | ||
| baseline := wn.Weight() | ||
|
|
||
| // Several picks that all report context.Canceled. | ||
| for i := 0; i < 4; i++ { | ||
| done = wn.Pick() | ||
| time.Sleep(time.Millisecond * 20) | ||
| done(context.Background(), selector.DoneInfo{Err: context.Canceled}) | ||
| } | ||
| if wn.Weight() < baseline*0.9 { | ||
| t.Errorf("context.Canceled should not degrade node weight: before=%.2f after=%.2f", | ||
| baseline, wn.Weight()) | ||
| } | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in b444c58. Now type-asserts |
||
|
|
||
| // --- context.DeadlineExceeded still degrades health --- | ||
| wn2 := newNode() | ||
| done = wn2.Pick() | ||
| time.Sleep(time.Millisecond * 20) | ||
| done(context.Background(), selector.DoneInfo{}) | ||
| baseline2 := wn2.Weight() | ||
|
|
||
| for i := 0; i < 4; i++ { | ||
| done = wn2.Pick() | ||
| time.Sleep(time.Millisecond * 20) | ||
| done(context.Background(), selector.DoneInfo{Err: context.DeadlineExceeded}) | ||
| } | ||
| if wn2.Weight() >= baseline2 { | ||
| t.Errorf("context.DeadlineExceeded should degrade node weight: before=%.2f after=%.2f", | ||
| baseline2, wn2.Weight()) | ||
| } | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in b444c58. Same approach — asserts on |
||
| } | ||
|
|
||
| func TestDirectErrorHandler(t *testing.T) { | ||
| b := &Builder{ | ||
| ErrHandler: func(err error) bool { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in b444c58. Changed to
errors.Is(di.Err, context.DeadlineExceeded)— correct stdlib/Kratos signature so wrapped deadline errors are matched properly.