@@ -5,6 +5,7 @@ package request
5
5
6
6
import (
7
7
"context"
8
+ "errors"
8
9
"io"
9
10
"math"
10
11
"sync"
@@ -13,6 +14,7 @@ import (
13
14
"github.com/Azure/kperf/api/types"
14
15
"github.com/Azure/kperf/metrics"
15
16
17
+ "golang.org/x/net/http2"
16
18
"golang.org/x/time/rate"
17
19
"k8s.io/client-go/rest"
18
20
"k8s.io/klog/v2"
@@ -81,6 +83,26 @@ func Schedule(ctx context.Context, spec *types.LoadProfileSpec, restCli []rest.I
81
83
if err == nil {
82
84
defer respBody .Close ()
83
85
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
+ }
84
106
}
85
107
latency := time .Since (start ).Seconds ()
86
108
@@ -119,3 +141,15 @@ func Schedule(ctx context.Context, spec *types.LoadProfileSpec, restCli []rest.I
119
141
Total : spec .Total ,
120
142
}, nil
121
143
}
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