Skip to content

Commit

Permalink
resources: Add timeout to the HTTP request in Get
Browse files Browse the repository at this point in the history
Workaround for golang/go#49366
  • Loading branch information
bep committed Dec 2, 2021
1 parent 6e3df83 commit 6573ba1
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions resources/resource_factories/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package create
import (
"bufio"
"bytes"
"context"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6573ba1

Please sign in to comment.