Mux: Send async mux ack and fix stream error responses (#19149)

Streams can return errors if the cancelation is picked up before the response 
stream close is picked up. Under extreme load, this could lead to missing 
responses.

Send server mux ack async so a blocked send cannot block newMuxStream 
call. Stream will not progress until mux has been acked.
This commit is contained in:
Klaus Post
2024-02-28 10:05:18 -08:00
committed by GitHub
parent 51874a5776
commit 40fb3371fa
4 changed files with 35 additions and 11 deletions

View File

@@ -74,10 +74,15 @@ func (s *Stream) Results(next func(b []byte) error) (err error) {
}
}
}()
doneCh := s.ctx.Done()
for {
select {
case <-s.ctx.Done():
return context.Cause(s.ctx)
case <-doneCh:
if err := context.Cause(s.ctx); !errors.Is(err, errStreamEOF) {
return err
}
// Fall through to be sure we have returned all responses.
doneCh = nil
case resp, ok := <-s.responses:
if !ok {
done = true