Fix mux client memory leak (#18956)

Add missing client cancellation, resulting in memory buildup tracing back to context.WithCancelCause/context.WithCancelDeadlineCause
This commit is contained in:
Klaus Post 2024-02-02 15:31:06 -08:00 committed by GitHub
parent ff80cfd83d
commit 63bf5f42a1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 3 deletions

View File

@ -287,6 +287,7 @@ func (c *Connection) newMuxClient(ctx context.Context) (*muxClient, error) {
if dl, ok := ctx.Deadline(); ok {
client.deadline = getDeadline(time.Until(dl))
if client.deadline == 0 {
client.cancelFn(context.DeadlineExceeded)
return nil, context.DeadlineExceeded
}
}
@ -333,6 +334,7 @@ func (c *Connection) Request(ctx context.Context, h HandlerID, req []byte) ([]by
_, ok := c.outgoing.Load(client.MuxID)
fmt.Println(client.MuxID, c.String(), "Connection.Request: DELETING MUX. Exists:", ok)
}
client.cancelFn(context.Canceled)
c.outgoing.Delete(client.MuxID)
}()
return client.traceRoundtrip(ctx, c.trace, h, req)

View File

@ -63,10 +63,11 @@ func (s *Stream) Send(b []byte) error {
func (s *Stream) Results(next func(b []byte) error) (err error) {
done := false
defer func() {
if s.cancel != nil {
s.cancel(err)
}
if !done {
if s.cancel != nil {
s.cancel(err)
}
// Drain channel.
for range s.responses {
}