Fix window update counting for the canceled streams

This commit is contained in:
iamqizhao
2016-04-12 11:06:27 -07:00
parent d07d0562ff
commit ccdc150c37
3 changed files with 25 additions and 0 deletions

View File

@ -196,6 +196,25 @@ func (f *inFlow) onData(n uint32) error {
return nil
}
// adjustConnPendingUpdate increments the connection level pending updates by n.
// This is called to make the proper connection level window updates when
// receiving data frame targeting the canceled RPCs.
func (f *inFlow) adjustConnPendingUpdate(n uint32) uint32 {
if n == 0 || f.conn != nil {
return 0
}
f.mu.Lock()
defer f.mu.Unlock()
f.pendingUpdate += n
if f.pendingUpdate >= f.limit/4 {
ret := f.pendingUpdate
f.pendingUpdate = 0
return ret
}
return 0
}
// connOnRead updates the connection level states when the application consumes data.
func (f *inFlow) connOnRead(n uint32) uint32 {
if n == 0 || f.conn != nil {

View File

@ -573,6 +573,9 @@ func (t *http2Client) handleData(f *http2.DataFrame) {
// Select the right stream to dispatch.
s, ok := t.getStream(f)
if !ok {
if cwu := t.fc.adjustConnPendingUpdate(uint32(len(f.Data()))); cwu > 0 {
t.controlBuf.put(&windowUpdate{0, cwu})
}
return
}
size := len(f.Data())

View File

@ -320,6 +320,9 @@ func (t *http2Server) handleData(f *http2.DataFrame) {
// Select the right stream to dispatch.
s, ok := t.getStream(f)
if !ok {
if cwu := t.fc.adjustConnPendingUpdate(uint32(len(f.Data()))); cwu > 0 {
t.controlBuf.put(&windowUpdate{0, cwu})
}
return
}
size := len(f.Data())