diff options
author | Bjørn Erik Pedersen <[email protected]> | 2021-12-02 14:13:24 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2021-12-02 16:11:14 +0100 |
commit | 93572e53181b5a614c2874bd00b7a38a02de58d3 (patch) | |
tree | c0bc0b13c21a88734dd4d0437bc1e9dd7ceb6c31 /resources/resource_factories | |
parent | 94f149b21e0c1d018e72cbea9e7d570785a512e9 (diff) | |
download | hugo-93572e53181b5a614c2874bd00b7a38a02de58d3.tar.gz hugo-93572e53181b5a614c2874bd00b7a38a02de58d3.zip |
resources: Add timeout to the HTTP request in Get
Workaround for https://github.com/golang/go/issues/49366
Diffstat (limited to 'resources/resource_factories')
-rw-r--r-- | resources/resource_factories/create/create.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/resources/resource_factories/create/create.go b/resources/resource_factories/create/create.go index 8edf501f7..9b8d73ad4 100644 --- a/resources/resource_factories/create/create.go +++ b/resources/resource_factories/create/create.go @@ -18,6 +18,7 @@ package create import ( "bufio" "bytes" + "context" "fmt" "io" "io/ioutil" @@ -180,6 +181,14 @@ func (c *Client) FromRemote(uri string, options map[string]interface{}) (resourc } addUserProvidedHeaders(headers, req) } + + // Workaround for https://github.com/golang/go/issues/49366 + // This is the entire lifetime of the request. + ctx, cancel := context.WithTimeout(req.Context(), 30*time.Second) + defer cancel() + + req = req.WithContext(ctx) + res, err := c.httpClient.Do(req) if err != nil { return nil, err |