fix: close http body for es action (#18491)

This commit is contained in:
jiuker 2023-11-21 14:22:10 +08:00 committed by GitHub
parent a4cfb5e1ed
commit 41091d9472
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -34,7 +34,7 @@ import (
elasticsearch7 "github.com/elastic/go-elasticsearch/v7" elasticsearch7 "github.com/elastic/go-elasticsearch/v7"
"github.com/minio/highwayhash" "github.com/minio/highwayhash"
"github.com/minio/minio/internal/event" "github.com/minio/minio/internal/event"
xioutil "github.com/minio/minio/internal/ioutil" xhttp "github.com/minio/minio/internal/http"
"github.com/minio/minio/internal/logger" "github.com/minio/minio/internal/logger"
"github.com/minio/minio/internal/once" "github.com/minio/minio/internal/once"
"github.com/minio/minio/internal/store" "github.com/minio/minio/internal/store"
@ -475,7 +475,7 @@ func (c *esClientV7) createIndex(args ElasticsearchArgs) error {
if err != nil { if err != nil {
return err return err
} }
defer xioutil.DiscardReader(resp.Body) defer xhttp.DrainBody(resp.Body)
if resp.IsError() { if resp.IsError() {
return fmt.Errorf("Create index err: %v", res) return fmt.Errorf("Create index err: %v", res)
} }
@ -491,7 +491,7 @@ func (c *esClientV7) ping(ctx context.Context, _ ElasticsearchArgs) (bool, error
if err != nil { if err != nil {
return false, store.ErrNotConnected return false, store.ErrNotConnected
} }
xioutil.DiscardReader(resp.Body) xhttp.DrainBody(resp.Body)
return !resp.IsError(), nil return !resp.IsError(), nil
} }
@ -504,7 +504,7 @@ func (c *esClientV7) entryExists(ctx context.Context, index string, key string)
if err != nil { if err != nil {
return false, err return false, err
} }
xioutil.DiscardReader(res.Body) xhttp.DrainBody(res.Body)
return !res.IsError(), nil return !res.IsError(), nil
} }
@ -519,7 +519,7 @@ func (c *esClientV7) removeEntry(ctx context.Context, index string, key string)
if err != nil { if err != nil {
return err return err
} }
defer xioutil.DiscardReader(res.Body) defer xhttp.DrainBody(res.Body)
if res.IsError() { if res.IsError() {
return fmt.Errorf("Delete err: %s", res.String()) return fmt.Errorf("Delete err: %s", res.String())
} }
@ -547,7 +547,7 @@ func (c *esClientV7) updateEntry(ctx context.Context, index string, key string,
if err != nil { if err != nil {
return err return err
} }
defer xioutil.DiscardReader(res.Body) defer xhttp.DrainBody(res.Body)
if res.IsError() { if res.IsError() {
return fmt.Errorf("Update err: %s", res.String()) return fmt.Errorf("Update err: %s", res.String())
} }
@ -573,7 +573,7 @@ func (c *esClientV7) addEntry(ctx context.Context, index string, eventData event
if err != nil { if err != nil {
return err return err
} }
defer xioutil.DiscardReader(res.Body) defer xhttp.DrainBody(res.Body)
if res.IsError() { if res.IsError() {
return fmt.Errorf("Add err: %s", res.String()) return fmt.Errorf("Add err: %s", res.String())
} }