Merge pull request #16 from iamqizhao/master

Deal with 0 timeout.
This commit is contained in:
Qi Zhao
2015-01-27 17:59:27 -08:00
2 changed files with 6 additions and 3 deletions

View File

@ -156,7 +156,7 @@ func (t *http2Server) operateHeaders(hDec *hpackDecoder, s *Stream, frame header
s.windowHandler = func(n int) {
t.addRecvQuota(s, n)
}
if hDec.state.timeout > 0 {
if hDec.state.timeoutSet {
s.ctx, s.cancel = context.WithTimeout(context.TODO(), hDec.state.timeout)
} else {
s.ctx, s.cancel = context.WithCancel(context.TODO())
@ -426,6 +426,7 @@ func (t *http2Server) WriteStatus(s *Stream, statusCode codes.Code, statusDesc s
}
s.mu.RUnlock()
if _, err := wait(s.ctx, t.shutdownChan, t.writableChan); err != nil {
// TODO(zhaoq): Print some errors using glog, e.g., glog.V(1).
return err
}
t.hBuf.Reset()

View File

@ -87,8 +87,9 @@ type decodeState struct {
statusCode codes.Code
statusDesc string
// Server side only fields.
timeout time.Duration
method string
timeoutSet bool
timeout time.Duration
method string
// key-value metadata map from the peer.
mdata map[string]string
}
@ -144,6 +145,7 @@ func newHPACKDecoder() *hpackDecoder {
case "grpc-message":
d.state.statusDesc = f.Value
case "grpc-timeout":
d.state.timeoutSet = true
var err error
d.state.timeout, err = timeoutDecode(f.Value)
if err != nil {