do right counting for max-streams flow control
This commit is contained in:
@ -105,7 +105,9 @@ type quotaPool struct {
|
|||||||
// newQuotaPool creates a quotaPool which has quota q available to consume.
|
// newQuotaPool creates a quotaPool which has quota q available to consume.
|
||||||
func newQuotaPool(q int) *quotaPool {
|
func newQuotaPool(q int) *quotaPool {
|
||||||
qb := "aPool{c: make(chan int, 1)}
|
qb := "aPool{c: make(chan int, 1)}
|
||||||
|
if q > 0 {
|
||||||
qb.c <- q
|
qb.c <- q
|
||||||
|
}
|
||||||
return qb
|
return qb
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,7 +196,7 @@ func newHTTP2Client(addr string, opts *ConnectOptions) (_ ClientTransport, err e
|
|||||||
return t, nil
|
return t, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *http2Client) newStream(ctx context.Context, callHdr *CallHdr, sq bool) *Stream {
|
func (t *http2Client) newStream(ctx context.Context, callHdr *CallHdr) *Stream {
|
||||||
fc := &inFlow{
|
fc := &inFlow{
|
||||||
limit: initialWindowSize,
|
limit: initialWindowSize,
|
||||||
conn: t.fc,
|
conn: t.fc,
|
||||||
@ -206,7 +206,6 @@ func (t *http2Client) newStream(ctx context.Context, callHdr *CallHdr, sq bool)
|
|||||||
id: t.nextID,
|
id: t.nextID,
|
||||||
method: callHdr.Method,
|
method: callHdr.Method,
|
||||||
buf: newRecvBuffer(),
|
buf: newRecvBuffer(),
|
||||||
updateStreams: sq,
|
|
||||||
fc: fc,
|
fc: fc,
|
||||||
sendQuotaPool: newQuotaPool(int(t.streamSendQuota)),
|
sendQuotaPool: newQuotaPool(int(t.streamSendQuota)),
|
||||||
headerChan: make(chan struct{}),
|
headerChan: make(chan struct{}),
|
||||||
@ -267,7 +266,7 @@ func (t *http2Client) NewStream(ctx context.Context, callHdr *CallHdr) (_ *Strea
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
t.mu.Lock()
|
t.mu.Lock()
|
||||||
s := t.newStream(ctx, callHdr, checkStreamsQuota)
|
s := t.newStream(ctx, callHdr)
|
||||||
t.activeStreams[s.id] = s
|
t.activeStreams[s.id] = s
|
||||||
t.mu.Unlock()
|
t.mu.Unlock()
|
||||||
// HPACK encodes various headers. Note that once WriteField(...) is
|
// HPACK encodes various headers. Note that once WriteField(...) is
|
||||||
@ -336,10 +335,14 @@ func (t *http2Client) NewStream(ctx context.Context, callHdr *CallHdr) (_ *Strea
|
|||||||
// CloseStream clears the footprint of a stream when the stream is not needed any more.
|
// CloseStream clears the footprint of a stream when the stream is not needed any more.
|
||||||
// This must not be executed in reader's goroutine.
|
// This must not be executed in reader's goroutine.
|
||||||
func (t *http2Client) CloseStream(s *Stream, err error) {
|
func (t *http2Client) CloseStream(s *Stream, err error) {
|
||||||
|
var updateStreams bool
|
||||||
t.mu.Lock()
|
t.mu.Lock()
|
||||||
|
if t.streamsQuota != nil {
|
||||||
|
updateStreams = true
|
||||||
|
}
|
||||||
delete(t.activeStreams, s.id)
|
delete(t.activeStreams, s.id)
|
||||||
t.mu.Unlock()
|
t.mu.Unlock()
|
||||||
if s.updateStreams {
|
if updateStreams {
|
||||||
t.streamsQuota.add(1)
|
t.streamsQuota.add(1)
|
||||||
}
|
}
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
@ -737,7 +740,7 @@ func (t *http2Client) applySettings(ss []http2.Setting) {
|
|||||||
t.mu.Lock()
|
t.mu.Lock()
|
||||||
reset := t.streamsQuota != nil
|
reset := t.streamsQuota != nil
|
||||||
if !reset {
|
if !reset {
|
||||||
t.streamsQuota = newQuotaPool(int(s.Val))
|
t.streamsQuota = newQuotaPool(int(s.Val) - len(t.activeStreams))
|
||||||
}
|
}
|
||||||
ms := t.maxStreams
|
ms := t.maxStreams
|
||||||
t.maxStreams = int(s.Val)
|
t.maxStreams = int(s.Val)
|
||||||
|
@ -172,12 +172,6 @@ type Stream struct {
|
|||||||
method string
|
method string
|
||||||
buf *recvBuffer
|
buf *recvBuffer
|
||||||
dec io.Reader
|
dec io.Reader
|
||||||
|
|
||||||
// updateStreams indicates whether the transport's streamsQuota needed
|
|
||||||
// to be updated when this stream is closed. It is false when the transport
|
|
||||||
// sticks to the initial infinite value of the number of concurrent streams.
|
|
||||||
// Ture otherwise.
|
|
||||||
updateStreams bool
|
|
||||||
fc *inFlow
|
fc *inFlow
|
||||||
recvQuota uint32
|
recvQuota uint32
|
||||||
// The accumulated inbound quota pending for window update.
|
// The accumulated inbound quota pending for window update.
|
||||||
|
Reference in New Issue
Block a user