Skip to content

Commit ac6b13c

Browse files
committed
Add a shorter timeout for mDNS IP lookup
Signed-off-by: Anders F Björklund <[email protected]>
1 parent 2e079a2 commit ac6b13c

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

pkg/limayaml/validate.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package limayaml
55

66
import (
7+
"context"
78
"errors"
89
"fmt"
910
"net"
@@ -16,6 +17,7 @@ import (
1617
"strconv"
1718
"strings"
1819
"unicode"
20+
"time"
1921

2022
"github.com/containerd/containerd/identifiers"
2123
"github.com/coreos/go-semver/semver"
@@ -569,12 +571,26 @@ func ValidateParamIsUsed(y *LimaYAML) error {
569571
return nil
570572
}
571573

574+
func lookupIP(host string) error {
575+
var err error
576+
if strings.HasSuffix(host, ".local") {
577+
var r net.Resolver
578+
const timeout = 500 * time.Millisecond // timeout for .local
579+
ctx, cancel := context.WithTimeout(context.TODO(), timeout)
580+
defer cancel()
581+
_, err = r.LookupIP(ctx, "ip", host)
582+
} else {
583+
_, err = net.LookupIP(host)
584+
}
585+
return err
586+
}
587+
572588
func validateHost(field, host string) error {
573589
if net.ParseIP(host) != nil {
574590
return nil
575591
}
576-
if _, err := net.LookupIP(host); err != nil {
577-
return fmt.Errorf("field `%s` must be IP", field)
592+
if err := lookupIP(host); err != nil {
593+
return fmt.Errorf("field `%s` must be IP: %w", field, err)
578594
}
579595
return nil
580596
}

0 commit comments

Comments
 (0)