Skip to content

Commit 6573ba1

Browse files
committed
resources: Add timeout to the HTTP request in Get
Workaround for golang/go#49366
1 parent 6e3df83 commit 6573ba1

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

resources/resource_factories/create/create.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package create
1818
import (
1919
"bufio"
2020
"bytes"
21+
"context"
2122
"fmt"
2223
"io"
2324
"io/ioutil"
@@ -180,6 +181,14 @@ func (c *Client) FromRemote(uri string, options map[string]interface{}) (resourc
180181
}
181182
addUserProvidedHeaders(headers, req)
182183
}
184+
185+
// Workaround for https://github.com/golang/go/issues/49366
186+
// This is the entire lifetime of the request.
187+
ctx, cancel := context.WithTimeout(req.Context(), 30*time.Second)
188+
defer cancel()
189+
190+
req = req.WithContext(ctx)
191+
183192
res, err := c.httpClient.Do(req)
184193
if err != nil {
185194
return nil, err

0 commit comments

Comments
 (0)