From 3d33dc8f5fe07b0d2e045a30c9379f93f061cde7 Mon Sep 17 00:00:00 2001 From: "alejandro.labad" Date: Mon, 23 Nov 2020 07:32:13 +0100 Subject: [PATCH 1/3] Fix - context timeout not launched on get bucket location #1413 --- bucket-cache.go | 1 + 1 file changed, 1 insertion(+) diff --git a/bucket-cache.go b/bucket-cache.go index 7d485a6b1c..5b95958487 100644 --- a/bucket-cache.go +++ b/bucket-cache.go @@ -102,6 +102,7 @@ func (c Client) getBucketLocation(ctx context.Context, bucketName string) (strin return "", err } + req = req.WithContext(ctx) // Initiate the request. resp, err := c.do(req) defer closeResponse(resp) From 593d6e901fe81aea710a5c2202667bbe0008efab Mon Sep 17 00:00:00 2001 From: "alejandro.labad" Date: Mon, 23 Nov 2020 08:06:21 +0100 Subject: [PATCH 2/3] Apply more elegan solution as suggested: http.NewRequestWithContext --- bucket-cache.go | 8 ++++---- bucket-cache_test.go | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/bucket-cache.go b/bucket-cache.go index 5b95958487..b84bacd27f 100644 --- a/bucket-cache.go +++ b/bucket-cache.go @@ -97,12 +97,12 @@ 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 } - req = req.WithContext(ctx) + //req = req.WithContext(ctx) // Initiate the request. resp, err := c.do(req) defer closeResponse(resp) @@ -170,7 +170,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", "") @@ -199,7 +199,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 b95857b367..1f1a4421f0 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()) } From e9956f90e3e29db461f5e946e989064403e9df14 Mon Sep 17 00:00:00 2001 From: "alejandro.labad" Date: Mon, 23 Nov 2020 08:22:00 +0100 Subject: [PATCH 3/3] Remove useless code --- bucket-cache.go | 1 - 1 file changed, 1 deletion(-) diff --git a/bucket-cache.go b/bucket-cache.go index b84bacd27f..156150f622 100644 --- a/bucket-cache.go +++ b/bucket-cache.go @@ -102,7 +102,6 @@ func (c Client) getBucketLocation(ctx context.Context, bucketName string) (strin return "", err } - //req = req.WithContext(ctx) // Initiate the request. resp, err := c.do(req) defer closeResponse(resp)