Skip to content

Commit b460c10

Browse files
committed
Set HTTP request timeout
1 parent 2203076 commit b460c10

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

pkg/alert/inspectalerts.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"io"
99
"net/http"
1010
"net/url"
11+
"time"
1112

1213
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1314
"k8s.io/apimachinery/pkg/util/errors"
@@ -46,12 +47,12 @@ func getWithRoundTripper(ctx context.Context, roundTripper http.RoundTripper, ge
4647
return nil, err
4748
}
4849

49-
client := &http.Client{Transport: roundTripper}
50+
client := &http.Client{Transport: roundTripper, Timeout: 15 * time.Second}
5051
errs := make([]error, 0, len(route.Status.Ingress))
5152
for _, ingress := range route.Status.Ingress {
5253
uri := *baseURI
5354
uri.Host = ingress.Host
54-
content, err := checkedGet(uri, client)
55+
content, err := checkedGet(ctx, uri, client)
5556
if err == nil {
5657
return content, nil
5758
} else {
@@ -67,8 +68,8 @@ func getWithRoundTripper(ctx context.Context, roundTripper http.RoundTripper, ge
6768

6869
}
6970

70-
func checkedGet(uri url.URL, client *http.Client) ([]byte, error) {
71-
req, err := http.NewRequest("GET", uri.String(), nil)
71+
func checkedGet(ctx context.Context, uri url.URL, client *http.Client) ([]byte, error) {
72+
req, err := http.NewRequestWithContext(ctx, "GET", uri.String(), nil)
7273
if err != nil {
7374
return nil, err
7475
}

0 commit comments

Comments
 (0)