Skip to content

Commit c5772de

Browse files
authored
request: ignore NO_ERROR (#139)
Signed-off-by: Wei Fu <weifu@microsoft.com>
1 parent 6b4fce2 commit c5772de

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

request/schedule.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package request
55

66
import (
77
"context"
8+
"errors"
89
"io"
910
"math"
1011
"sync"
@@ -13,6 +14,7 @@ import (
1314
"github.com/Azure/kperf/api/types"
1415
"github.com/Azure/kperf/metrics"
1516

17+
"golang.org/x/net/http2"
1618
"golang.org/x/time/rate"
1719
"k8s.io/client-go/rest"
1820
"k8s.io/klog/v2"
@@ -81,6 +83,26 @@ func Schedule(ctx context.Context, spec *types.LoadProfileSpec, restCli []rest.I
8183
if err == nil {
8284
defer respBody.Close()
8385
bytes, err = io.Copy(io.Discard, respBody)
86+
87+
// Based on HTTP2 Spec Section 8.1 [1],
88+
//
89+
// A server can send a complete response prior to the client
90+
// sending an entire request if the response does not depend
91+
// on any portion of the request that has not been sent and
92+
// received. When this is true, a server MAY request that the
93+
// client abort transmission of a request without error by
94+
// sending a RST_STREAM with an error code of NO_ERROR after
95+
// sending a complete response (i.e., a frame with the END_STREAM
96+
// flag). Clients MUST NOT discard responses as a result of receiving
97+
// such a RST_STREAM, though clients can always discard responses
98+
// at their discretion for other reasons.
99+
//
100+
// We should mark NO_ERROR as nil here.
101+
//
102+
// [1]: https://httpwg.org/specs/rfc7540.html#HttpSequence
103+
if err != nil && isHTTP2StreamNoError(err) {
104+
err = nil
105+
}
84106
}
85107
latency := time.Since(start).Seconds()
86108

@@ -119,3 +141,15 @@ func Schedule(ctx context.Context, spec *types.LoadProfileSpec, restCli []rest.I
119141
Total: spec.Total,
120142
}, nil
121143
}
144+
145+
// isHTTP2StreamNoError returns true if it's NO_ERROR.
146+
func isHTTP2StreamNoError(err error) bool {
147+
if err == nil {
148+
return false
149+
}
150+
151+
if streamErr, ok := err.(http2.StreamError); ok || errors.As(err, &streamErr) {
152+
return streamErr.Code == http2.ErrCodeNo
153+
}
154+
return false
155+
}

0 commit comments

Comments
 (0)