mirror of
https://github.com/minio/minio.git
synced 2024-12-24 06:05:55 -05:00
fix: avoid goroutine leak after timeouts in PeerMetrics (#16569)
This commit is contained in:
parent
c97f50e274
commit
1828fb212a
@ -838,14 +838,20 @@ func (client *peerRESTClient) GetPeerMetrics(ctx context.Context) (<-chan Metric
|
||||
dec := gob.NewDecoder(respBody)
|
||||
ch := make(chan Metric)
|
||||
go func(ch chan<- Metric) {
|
||||
defer func() {
|
||||
xhttp.DrainBody(respBody)
|
||||
close(ch)
|
||||
}()
|
||||
for {
|
||||
var metric Metric
|
||||
if err := dec.Decode(&metric); err != nil {
|
||||
xhttp.DrainBody(respBody)
|
||||
close(ch)
|
||||
return
|
||||
}
|
||||
ch <- metric
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case ch <- metric:
|
||||
}
|
||||
}
|
||||
}(ch)
|
||||
return ch, nil
|
||||
|
Loading…
Reference in New Issue
Block a user