Skip to content

Commit 19a0ef8

Browse files
owainlewisprydie
authored andcommitted
Add default HTTP timeout to metadata client. (#277)
1 parent 5808f4a commit 19a0ef8

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

pkg/oci/instance/metadata/instance_metadata.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ package metadata
1717
import (
1818
"encoding/json"
1919
"net/http"
20+
"time"
2021

2122
"github.com/pkg/errors"
2223
)
2324

2425
const (
25-
baseURL = "http://169.254.169.254"
26-
metadataEndpoint = "/opc/v1/instance/"
26+
baseURL = "http://169.254.169.254"
27+
metadataEndpoint = "/opc/v1/instance/"
28+
defaultHTTPTimeout = 5 * time.Second
2729
)
2830

2931
// InstanceMetadata holds the subset of the instance metadata retrieved from the
@@ -48,7 +50,8 @@ type metadataGetter struct {
4850
// New returns the instance metadata for the host on which the code is being
4951
// executed.
5052
func New() Interface {
51-
return &metadataGetter{client: http.DefaultClient, baseURL: baseURL}
53+
var client = &http.Client{Timeout: defaultHTTPTimeout}
54+
return &metadataGetter{client: client, baseURL: baseURL}
5255
}
5356

5457
// Get either returns the cached metadata for the current instance or queries

0 commit comments

Comments
 (0)