Skip to content

Commit b34f845

Browse files
authored
server: allow 0s grpc-timeout header values, as java is known to be able to send them (#8439) (#8440)
1 parent 1787f94 commit b34f845

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

internal/transport/http2_server.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,10 +600,24 @@ func (t *http2Server) operateHeaders(ctx context.Context, frame *http2.MetaHeade
600600
return nil
601601
}
602602
}
603+
604+
if s.ctx.Err() != nil {
605+
// Early abort in case the timeout was zero or so low it already fired.
606+
t.controlBuf.put(&earlyAbortStream{
607+
httpStatus: http.StatusOK,
608+
streamID: s.id,
609+
contentSubtype: s.contentSubtype,
610+
status: status.New(codes.DeadlineExceeded, context.DeadlineExceeded.Error()),
611+
rst: !frame.StreamEnded(),
612+
})
613+
return nil
614+
}
615+
603616
t.activeStreams[streamID] = s
604617
if len(t.activeStreams) == 1 {
605618
t.idle = time.Time{}
606619
}
620+
607621
// Start a timer to close the stream on reaching the deadline.
608622
if timeoutSet {
609623
// We need to wait for s.cancel to be updated before calling

internal/transport/http_util.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,6 @@ func decodeTimeout(s string) (time.Duration, error) {
200200
if err != nil {
201201
return 0, err
202202
}
203-
if t == 0 {
204-
return 0, fmt.Errorf("transport: timeout must be positive: %q", s)
205-
}
206203
const maxHours = math.MaxInt64 / uint64(time.Hour)
207204
if d == time.Hour && t > maxHours {
208205
// This timeout would overflow math.MaxInt64; clamp it.

internal/transport/http_util_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ func (s) TestDecodeTimeout(t *testing.T) {
5656
{"1", 0, true},
5757
{"", 0, true},
5858
{"9a1S", 0, true},
59-
{"0S", 0, true}, // PROTOCOL-HTTP2.md requires positive integers
60-
{"00000000S", 0, true},
61-
{"000000000S", 0, true},
59+
{"0S", 0, false}, // PROTOCOL-HTTP2.md requires positive integers, but we allow it to timeout instead
60+
{"00000000S", 0, false},
61+
{"000000000S", 0, true}, // PROTOCOL-HTTP2.md allows at most 8 digits
6262
} {
6363
d, err := decodeTimeout(test.s)
6464
gotErr := err != nil

0 commit comments

Comments
 (0)