Skip to content

Commit 53fb4a2

Browse files
authored
fix(api): add a global timeout when checking network requirement (#5070)
1 parent c93784b commit 53fb4a2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

sdk/requirement.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package sdk
22

33
import (
4+
"context"
45
"net"
56
"time"
67
)
@@ -177,7 +178,11 @@ func (a *Action) Requirement(name string, t string, value string) *Action {
177178

178179
// CheckNetworkAccessRequirement returns true if req.Value can Dial
179180
func CheckNetworkAccessRequirement(req Requirement) bool {
180-
conn, err := net.DialTimeout("tcp", req.Value, 10*time.Second)
181+
d := net.Dialer{Timeout: 10 * time.Second}
182+
ctx, cancel := context.WithTimeout(context.Background(), d.Timeout)
183+
defer cancel()
184+
185+
conn, err := d.DialContext(ctx, "tcp", req.Value)
181186
if err != nil {
182187
return false
183188
}

0 commit comments

Comments
 (0)