Skip to content

Commit aa13dc0

Browse files
committed
Fix for grpc frame too large and context closed warning
Signed-off-by: Balaji Vijayakumar <[email protected]>
1 parent 56fb5fa commit aa13dc0

File tree

4 files changed

+59
-5
lines changed

4 files changed

+59
-5
lines changed

Diff for: pkg/guestagent/api/client/client.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"context"
55
"net"
66

7-
"google.golang.org/grpc/credentials/insecure"
8-
97
"github.com/lima-vm/lima/pkg/guestagent/api"
108
"google.golang.org/grpc"
119
"google.golang.org/protobuf/types/known/emptypb"
@@ -20,7 +18,7 @@ func NewGuestAgentClient(dialFn func(ctx context.Context) (net.Conn, error)) (*G
2018
grpc.WithContextDialer(func(ctx context.Context, target string) (net.Conn, error) {
2119
return dialFn(ctx)
2220
}),
23-
grpc.WithTransportCredentials(insecure.NewCredentials()),
21+
grpc.WithTransportCredentials(NewCredentials()),
2422
}
2523

2624
clientConn, err := grpc.Dial("", opts...)

Diff for: pkg/guestagent/api/client/credentials.go

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package client
2+
3+
import (
4+
"context"
5+
"net"
6+
7+
"google.golang.org/grpc/credentials"
8+
)
9+
10+
// NewCredentials returns a lima credential implementing credentials.TransportCredentials.
11+
func NewCredentials() credentials.TransportCredentials {
12+
return &secureTC{
13+
info: credentials.ProtocolInfo{
14+
SecurityProtocol: "local",
15+
},
16+
}
17+
}
18+
19+
// secureTC is the credentials required to establish a lima guest connection.
20+
type secureTC struct {
21+
info credentials.ProtocolInfo
22+
}
23+
24+
func (c *secureTC) Info() credentials.ProtocolInfo {
25+
return c.info
26+
}
27+
28+
func (*secureTC) ClientHandshake(_ context.Context, _ string, conn net.Conn) (net.Conn, credentials.AuthInfo, error) {
29+
return conn, info{credentials.CommonAuthInfo{SecurityLevel: credentials.PrivacyAndIntegrity}}, nil
30+
}
31+
32+
func (*secureTC) ServerHandshake(conn net.Conn) (net.Conn, credentials.AuthInfo, error) {
33+
return conn, info{credentials.CommonAuthInfo{SecurityLevel: credentials.PrivacyAndIntegrity}}, nil
34+
}
35+
36+
func (c *secureTC) Clone() credentials.TransportCredentials {
37+
return &secureTC{info: c.info}
38+
}
39+
40+
func (c *secureTC) OverrideServerName(serverNameOverride string) error {
41+
c.info.ServerName = serverNameOverride
42+
return nil
43+
}
44+
45+
type info struct {
46+
credentials.CommonAuthInfo
47+
}
48+
49+
func (info) AuthType() string {
50+
return "local"
51+
}

Diff for: pkg/hostagent/hostagent.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import (
1616
"sync"
1717
"time"
1818

19+
"google.golang.org/grpc/codes"
20+
"google.golang.org/grpc/status"
21+
1922
"github.com/lima-vm/lima/pkg/driver"
2023
"github.com/lima-vm/lima/pkg/driverutil"
2124
"github.com/lima-vm/lima/pkg/networks"
@@ -595,7 +598,7 @@ func (a *HostAgent) watchGuestAgentEvents(ctx context.Context) {
595598
if err == nil {
596599
if err := a.processGuestAgentEvents(ctx, client); err != nil {
597600
if !errors.Is(err, context.Canceled) {
598-
logrus.WithError(err).Warn("connection to the guest agent was closed unexpectedly", err)
601+
logrus.WithError(err).Warn("guest agent events closed unexpectedly", err)
599602
}
600603
}
601604
} else {
@@ -658,6 +661,9 @@ func (a *HostAgent) processGuestAgentEvents(ctx context.Context, client *guestag
658661
}
659662

660663
if err := client.Events(ctx, onEvent); err != nil {
664+
if status.Code(err) == codes.Canceled {
665+
return context.Canceled
666+
}
661667
return err
662668
}
663669
return io.EOF

Diff for: pkg/vz/network_darwin.go

-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ func (v *QEMUPacketConn) Read(b []byte) (n int, err error) {
7979
size := binary.BigEndian.Uint32(header)
8080
reader := io.LimitReader(v.unixConn, int64(size))
8181
_, err = reader.Read(b)
82-
8382
if err != nil {
8483
logrus.Errorln("Failed to read packet", err)
8584
}

0 commit comments

Comments
 (0)