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

request: ignore NO_ERROR #139

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions request/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package request

import (
"context"
"errors"
"io"
"math"
"sync"
Expand All @@ -13,6 +14,7 @@ import (
"github.com/Azure/kperf/api/types"
"github.com/Azure/kperf/metrics"

"golang.org/x/net/http2"
"golang.org/x/time/rate"
"k8s.io/client-go/rest"
"k8s.io/klog/v2"
Expand Down Expand Up @@ -81,6 +83,26 @@ func Schedule(ctx context.Context, spec *types.LoadProfileSpec, restCli []rest.I
if err == nil {
defer respBody.Close()
bytes, err = io.Copy(io.Discard, respBody)

// Based on HTTP2 Spec Section 8.1 [1],
//
// A server can send a complete response prior to the client
// sending an entire request if the response does not depend
// on any portion of the request that has not been sent and
// received. When this is true, a server MAY request that the
// client abort transmission of a request without error by
// sending a RST_STREAM with an error code of NO_ERROR after
// sending a complete response (i.e., a frame with the END_STREAM
// flag). Clients MUST NOT discard responses as a result of receiving
// such a RST_STREAM, though clients can always discard responses
// at their discretion for other reasons.
//
// We should mark NO_ERROR as nil here.
//
// [1]: https://httpwg.org/specs/rfc7540.html#HttpSequence
if err != nil && isHTTP2StreamNoError(err) {
err = nil
}
}
latency := time.Since(start).Seconds()

Expand Down Expand Up @@ -119,3 +141,15 @@ func Schedule(ctx context.Context, spec *types.LoadProfileSpec, restCli []rest.I
Total: spec.Total,
}, nil
}

// isHTTP2StreamNoError returns true if it's NO_ERROR.
func isHTTP2StreamNoError(err error) bool {
if err == nil {
return false
}

if streamErr, ok := err.(http2.StreamError); ok || errors.As(err, &streamErr) {
return streamErr.Code == http2.ErrCodeNo
}
return false
}