summaryrefslogtreecommitdiffstats
path: root/resources
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2021-12-02 14:13:24 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2021-12-02 16:11:14 +0100
commit93572e53181b5a614c2874bd00b7a38a02de58d3 (patch)
treec0bc0b13c21a88734dd4d0437bc1e9dd7ceb6c31 /resources
parent94f149b21e0c1d018e72cbea9e7d570785a512e9 (diff)
resources: Add timeout to the HTTP request in Get
Workaround for https://github.com/golang/go/issues/49366
Diffstat (limited to 'resources')
-rw-r--r--resources/resource_factories/create/create.go9
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