mirror of
https://github.com/minio/minio.git
synced 2025-04-22 03:24:38 -04: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)
|
dec := gob.NewDecoder(respBody)
|
||||||
ch := make(chan Metric)
|
ch := make(chan Metric)
|
||||||
go func(ch chan<- Metric) {
|
go func(ch chan<- Metric) {
|
||||||
|
defer func() {
|
||||||
|
xhttp.DrainBody(respBody)
|
||||||
|
close(ch)
|
||||||
|
}()
|
||||||
for {
|
for {
|
||||||
var metric Metric
|
var metric Metric
|
||||||
if err := dec.Decode(&metric); err != nil {
|
if err := dec.Decode(&metric); err != nil {
|
||||||
xhttp.DrainBody(respBody)
|
|
||||||
close(ch)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ch <- metric
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return
|
||||||
|
case ch <- metric:
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}(ch)
|
}(ch)
|
||||||
return ch, nil
|
return ch, nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user