From 305f6bd5dae939c335020c31c2d7b345d3fed45e Mon Sep 17 00:00:00 2001 From: Doug Fawley Date: Thu, 18 Apr 2024 09:37:08 -0700 Subject: [PATCH] small reorder for more clarity --- internal/transport/http2_client.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/transport/http2_client.go b/internal/transport/http2_client.go index efc8186bd330..3c63c706986d 100644 --- a/internal/transport/http2_client.go +++ b/internal/transport/http2_client.go @@ -808,13 +808,15 @@ func (t *http2Client) NewStream(ctx context.Context, callHdr *CallHdr) (*Stream, t.waitingStreams-- } t.streamQuota-- + t.mu.Lock() - hdr.streamID = t.nextID - t.nextID += 2 if t.state == draining || t.activeStreams == nil { // Can be niled from Close(). t.mu.Unlock() return false // Don't create a stream if the transport is already closed. } + + hdr.streamID = t.nextID + t.nextID += 2 // Drain client transport if nextID > MaxStreamID which signals gRPC that // the connection is closed and a new one must be created for subsequent RPCs. transportDrainRequired = t.nextID > MaxStreamID @@ -823,6 +825,7 @@ func (t *http2Client) NewStream(ctx context.Context, callHdr *CallHdr) (*Stream, s.fc = &inFlow{limit: uint32(t.initialWindowSize)} t.activeStreams[s.id] = s t.mu.Unlock() + if t.streamQuota > 0 && t.waitingStreams > 0 { select { case t.streamsQuotaAvailable <- struct{}{}: