Skip to content
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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Revolution1
Copy link

@Revolution1 Revolution1 commented Dec 3, 2024

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.

@Revolution1 Revolution1 requested a review from a team as a code owner December 3, 2024 11:36
@Revolution1 Revolution1 requested a review from zhwrd December 3, 2024 11:36
Comment on lines +589 to +591
if errors.Is(err, context.Canceled) {
return nil, err
}
Copy link
Contributor

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) {
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit; canceld -> canceled

@jelias2
Copy link
Contributor

jelias2 commented Dec 11, 2024

Left a few comments, overall looks good! Thanks for the contribution @Revolution1!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants