mirror of
https://github.com/minio/minio.git
synced 2025-05-21 09:33:50 -04:00
fix: Avoid Income globalStats twice upon error (#17263)
This commit is contained in:
parent
2920b0fc6d
commit
b1b00a5055
@ -201,25 +201,30 @@ func (c *Client) newRequest(ctx context.Context, u *url.URL, body io.Reader) (*h
|
|||||||
|
|
||||||
type respBodyMonitor struct {
|
type respBodyMonitor struct {
|
||||||
io.ReadCloser
|
io.ReadCloser
|
||||||
expectTimeouts bool
|
expectTimeouts bool
|
||||||
|
errorStatusOnce sync.Once
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r respBodyMonitor) Read(p []byte) (n int, err error) {
|
func (r *respBodyMonitor) Read(p []byte) (n int, err error) {
|
||||||
n, err = r.ReadCloser.Read(p)
|
n, err = r.ReadCloser.Read(p)
|
||||||
if xnet.IsNetworkOrHostDown(err, r.expectTimeouts) {
|
r.errorStatus(err)
|
||||||
atomic.AddUint64(&globalStats.errs, 1)
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r respBodyMonitor) Close() (err error) {
|
func (r *respBodyMonitor) Close() (err error) {
|
||||||
err = r.ReadCloser.Close()
|
err = r.ReadCloser.Close()
|
||||||
if xnet.IsNetworkOrHostDown(err, r.expectTimeouts) {
|
r.errorStatus(err)
|
||||||
atomic.AddUint64(&globalStats.errs, 1)
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *respBodyMonitor) errorStatus(err error) {
|
||||||
|
if xnet.IsNetworkOrHostDown(err, r.expectTimeouts) {
|
||||||
|
r.errorStatusOnce.Do(func() {
|
||||||
|
atomic.AddUint64(&globalStats.errs, 1)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Call - make a REST call with context.
|
// Call - make a REST call with context.
|
||||||
func (c *Client) Call(ctx context.Context, method string, values url.Values, body io.Reader, length int64) (reply io.ReadCloser, err error) {
|
func (c *Client) Call(ctx context.Context, method string, values url.Values, body io.Reader, length int64) (reply io.ReadCloser, err error) {
|
||||||
urlStr := c.url.String()
|
urlStr := c.url.String()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user