From 26addf203d4a7d73e33f0731b67a7c02a910632a Mon Sep 17 00:00:00 2001 From: alexcocia Date: Mon, 23 Nov 2020 11:59:58 +0100 Subject: [PATCH] fix: context timeout not launched on get bucket location #1413 (#1414) --- bucket-cache.go | 6 +++--- bucket-cache_test.go | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/bucket-cache.go b/bucket-cache.go index 7d485a6b1..156150f62 100644 --- a/bucket-cache.go +++ b/bucket-cache.go @@ -97,7 +97,7 @@ func (c Client) getBucketLocation(ctx context.Context, bucketName string) (strin } // Initialize a new request. - req, err := c.getBucketLocationRequest(bucketName) + req, err := c.getBucketLocationRequest(ctx, bucketName) if err != nil { return "", err } @@ -169,7 +169,7 @@ func processBucketLocationResponse(resp *http.Response, bucketName string) (buck } // getBucketLocationRequest - Wrapper creates a new getBucketLocation request. -func (c Client) getBucketLocationRequest(bucketName string) (*http.Request, error) { +func (c Client) getBucketLocationRequest(ctx context.Context, bucketName string) (*http.Request, error) { // Set location query. urlValues := make(url.Values) urlValues.Set("location", "") @@ -198,7 +198,7 @@ func (c Client) getBucketLocationRequest(bucketName string) (*http.Request, erro } // Get a new HTTP request for the method. - req, err := http.NewRequest(http.MethodGet, urlStr, nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, urlStr, nil) if err != nil { return nil, err } diff --git a/bucket-cache_test.go b/bucket-cache_test.go index b95857b36..1f1a4421f 100644 --- a/bucket-cache_test.go +++ b/bucket-cache_test.go @@ -19,6 +19,7 @@ package minio import ( "bytes" + "context" "encoding/xml" "io/ioutil" "net/http" @@ -236,7 +237,7 @@ func TestGetBucketLocationRequest(t *testing.T) { } } - actualReq, err := client.getBucketLocationRequest(testCase.bucketName) + actualReq, err := client.getBucketLocationRequest(context.Background(), testCase.bucketName) if err != nil && testCase.shouldPass { t.Errorf("Test %d: Expected to pass, but failed with: %s", i+1, err.Error()) }