Skip to content

Commit 05b4893

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

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
@@ -1,6 +1,7 @@
11
package limayaml
22

33
import (
4+
"context"
45
"errors"
56
"fmt"
67
"net"
@@ -10,6 +11,7 @@ import (
1011
"regexp"
1112
"runtime"
1213
"strings"
14+
"time"
1315

1416
"github.com/docker/go-units"
1517
"github.com/lima-vm/lima/pkg/localpathutil"
@@ -436,12 +438,26 @@ func ValidateParamIsUsed(y *LimaYAML) error {
436438
return nil
437439
}
438440

441+
func lookupIP(host string) error {
442+
var err error
443+
if strings.HasSuffix(host, ".local") {
444+
var r net.Resolver
445+
const timeout = 500 * time.Millisecond // timeout for .local
446+
ctx, cancel := context.WithTimeout(context.TODO(), timeout)
447+
defer cancel()
448+
_, err = r.LookupIP(ctx, "ip", host)
449+
} else {
450+
_, err = net.LookupIP(host)
451+
}
452+
return err
453+
}
454+
439455
func validateHost(field, host string) error {
440456
if net.ParseIP(host) != nil {
441457
return nil
442458
}
443-
if _, err := net.LookupIP(host); err != nil {
444-
return fmt.Errorf("field `%s` must be IP", field)
459+
if err := lookupIP(host); err != nil {
460+
return fmt.Errorf("field `%s` must be IP: %w", field, err)
445461
}
446462
return nil
447463
}

0 commit comments

Comments
 (0)