Skip to content

Commit

Permalink
Merge pull request #2219 from balajiv113/grpc-fixes
Browse files Browse the repository at this point in the history
Fix for GRPC frame too large and context closed warning
  • Loading branch information
AkihiroSuda authored Feb 23, 2024
2 parents 81482b1 + aa13dc0 commit 0b0f0f1
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 5 deletions.
4 changes: 1 addition & 3 deletions pkg/guestagent/api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"context"
"net"

"google.golang.org/grpc/credentials/insecure"

"github.com/lima-vm/lima/pkg/guestagent/api"
"google.golang.org/grpc"
"google.golang.org/protobuf/types/known/emptypb"
Expand All @@ -20,7 +18,7 @@ func NewGuestAgentClient(dialFn func(ctx context.Context) (net.Conn, error)) (*G
grpc.WithContextDialer(func(ctx context.Context, target string) (net.Conn, error) {
return dialFn(ctx)
}),
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithTransportCredentials(NewCredentials()),
}

clientConn, err := grpc.Dial("", opts...)
Expand Down
51 changes: 51 additions & 0 deletions pkg/guestagent/api/client/credentials.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package client

import (
"context"
"net"

"google.golang.org/grpc/credentials"
)

// NewCredentials returns a lima credential implementing credentials.TransportCredentials.
func NewCredentials() credentials.TransportCredentials {
return &secureTC{
info: credentials.ProtocolInfo{
SecurityProtocol: "local",
},
}
}

// secureTC is the credentials required to establish a lima guest connection.
type secureTC struct {
info credentials.ProtocolInfo
}

func (c *secureTC) Info() credentials.ProtocolInfo {
return c.info
}

func (*secureTC) ClientHandshake(_ context.Context, _ string, conn net.Conn) (net.Conn, credentials.AuthInfo, error) {
return conn, info{credentials.CommonAuthInfo{SecurityLevel: credentials.PrivacyAndIntegrity}}, nil
}

func (*secureTC) ServerHandshake(conn net.Conn) (net.Conn, credentials.AuthInfo, error) {
return conn, info{credentials.CommonAuthInfo{SecurityLevel: credentials.PrivacyAndIntegrity}}, nil
}

func (c *secureTC) Clone() credentials.TransportCredentials {
return &secureTC{info: c.info}
}

func (c *secureTC) OverrideServerName(serverNameOverride string) error {
c.info.ServerName = serverNameOverride
return nil
}

type info struct {
credentials.CommonAuthInfo
}

func (info) AuthType() string {
return "local"
}
8 changes: 7 additions & 1 deletion pkg/hostagent/hostagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import (
"sync"
"time"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/lima-vm/lima/pkg/driver"
"github.com/lima-vm/lima/pkg/driverutil"
"github.com/lima-vm/lima/pkg/networks"
Expand Down Expand Up @@ -595,7 +598,7 @@ func (a *HostAgent) watchGuestAgentEvents(ctx context.Context) {
if err == nil {
if err := a.processGuestAgentEvents(ctx, client); err != nil {
if !errors.Is(err, context.Canceled) {
logrus.WithError(err).Warn("connection to the guest agent was closed unexpectedly", err)
logrus.WithError(err).Warn("guest agent events closed unexpectedly", err)
}
}
} else {
Expand Down Expand Up @@ -658,6 +661,9 @@ func (a *HostAgent) processGuestAgentEvents(ctx context.Context, client *guestag
}

if err := client.Events(ctx, onEvent); err != nil {
if status.Code(err) == codes.Canceled {
return context.Canceled
}
return err
}
return io.EOF
Expand Down
1 change: 0 additions & 1 deletion pkg/vz/network_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ func (v *QEMUPacketConn) Read(b []byte) (n int, err error) {
size := binary.BigEndian.Uint32(header)
reader := io.LimitReader(v.unixConn, int64(size))
_, err = reader.Read(b)

if err != nil {
logrus.Errorln("Failed to read packet", err)
}
Expand Down

0 comments on commit 0b0f0f1

Please sign in to comment.