-
Notifications
You must be signed in to change notification settings - Fork 30
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
fix: exclude context canccel error from forward error counting #98
base: main
Are you sure you want to change the base?
fix: exclude context canccel error from forward error counting #98
Conversation
if errors.Is(err, context.Canceled) { | ||
return nil, err | ||
} |
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.
Would it be possible to add a metric for canceled contexts here?
@@ -20,3 +26,34 @@ func TestStripXFF(t *testing.T) { | |||
assert.Equal(t, test.out, actual) | |||
} | |||
} | |||
|
|||
func TestForwardContextCanceled(t *testing.T) { |
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.
Looks good, would it be possible to add a few more tests and cases such as incrementing the intermittentErrorsSlidingWindow first and then checking that they are not incremented again.
Maybe asset that the debug log exists too in the case of context canceled.
Also test the multicall routing strategy
@@ -583,6 +585,10 @@ func (b *Backend) doForward(ctx context.Context, rpcReqs []*RPCReq, isBatch bool | |||
start := time.Now() | |||
httpRes, err := b.client.DoLimited(httpReq) | |||
if err != nil { | |||
// if it's canceld, we don't want to count it as an error |
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.
nit; canceld -> canceled
Left a few comments, overall looks good! Thanks for the contribution @Revolution1! |
Description
Proxyd bans backends based on its error rate.
But it even counts context canceled error as a forwarding error,
while the cancellation is actually triggered by incomplete HTTP requests from the client.
This means hackers can make DoS attacks by just sendinga bunch of requests and closing without waiting for a response.
Tests
We have an environment that client sends a lot this kind of requests to test connection or some thing.
Before this patch:
the proxy will have no backends to serve in a very short time.
After:
works like a charm.
BTW:
wrapErr()
will strip the error's type.It's recommended to use this package to do error wrapping and assertion.