Skip to content

Commit 424519b

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

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"
@@ -9,6 +10,7 @@ import (
910
"path/filepath"
1011
"runtime"
1112
"strings"
13+
"time"
1214

1315
"github.com/docker/go-units"
1416
"github.com/lima-vm/lima/pkg/localpathutil"
@@ -451,12 +453,26 @@ func validateNetwork(y LimaYAML, warn bool) error {
451453
return nil
452454
}
453455

456+
func lookupIP(host string) error {
457+
var err error
458+
if strings.HasSuffix(host, ".local") {
459+
var r net.Resolver
460+
const timeout = 500 * time.Millisecond // timeout for .local
461+
ctx, cancel := context.WithTimeout(context.TODO(), timeout)
462+
defer cancel()
463+
_, err = r.LookupIP(ctx, "ip", host)
464+
} else {
465+
_, err = net.LookupIP(host)
466+
}
467+
return err
468+
}
469+
454470
func validateHost(field, host string) error {
455471
if net.ParseIP(host) != nil {
456472
return nil
457473
}
458-
if _, err := net.LookupIP(host); err != nil {
459-
return fmt.Errorf("field `%s` must be IP", field)
474+
if err := lookupIP(host); err != nil {
475+
return fmt.Errorf("field `%s` must be IP: %w", field, err)
460476
}
461477
return nil
462478
}

0 commit comments

Comments
 (0)