Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix - context timeout not launched on get bucket location #1413 #1414

Merged
merged 3 commits into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions bucket-cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +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)
// Initiate the request.
resp, err := c.do(req)
defer closeResponse(resp)
Expand Down Expand Up @@ -169,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", "")
Expand Down Expand Up @@ -198,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
}
Expand Down
3 changes: 2 additions & 1 deletion bucket-cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package minio

import (
"bytes"
"context"
"encoding/xml"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -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: <ERROR> %s", i+1, err.Error())
}
Expand Down