Skip to content

Commit

Permalink
Increased gRPC message size limit to 16MB / added CLI flag to set the…
Browse files Browse the repository at this point in the history
… value (#2729)

* Removed globals in daemon command args parsing

* Increased gRPC message size limit to 16MB / added CLI flag to set the value
  • Loading branch information
cmaglie authored Oct 11, 2024
1 parent ea09108 commit 0540cee
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
28 changes: 18 additions & 10 deletions internal/cli/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,14 @@ import (
"google.golang.org/grpc"
)

var (
daemonize bool
debug bool
debugFile string
debugFilters []string
)

// NewCommand created a new `daemon` command
func NewCommand(srv rpc.ArduinoCoreServiceServer, settings *rpc.Configuration) *cobra.Command {
var daemonize bool
var debug bool
var debugFile string
var debugFiltersArg []string
var daemonPort string
var maxGRPCRecvMsgSize int
daemonCommand := &cobra.Command{
Use: "daemon",
Short: i18n.Tr("Run the Arduino CLI as a gRPC daemon."),
Expand All @@ -63,9 +61,14 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer, settings *rpc.Configuration) *
panic("Failed to set default value for directories.builtin.libraries: " + err.Error())
}
}

// Validate the maxGRPCRecvMsgSize flag
if maxGRPCRecvMsgSize < 1024 {
feedback.Fatal(i18n.Tr("%s must be >= 1024", "--max-grpc-recv-message-size"), feedback.ErrBadArgument)
}
},
Run: func(cmd *cobra.Command, args []string) {
runDaemonCommand(srv, daemonPort)
runDaemonCommand(srv, daemonPort, debugFile, debug, daemonize, debugFiltersArg, maxGRPCRecvMsgSize)
},
}
defaultDaemonPort := settings.GetDaemon().GetPort()
Expand All @@ -82,13 +85,16 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer, settings *rpc.Configuration) *
daemonCommand.Flags().StringVar(&debugFile,
"debug-file", "",
i18n.Tr("Append debug logging to the specified file"))
daemonCommand.Flags().StringSliceVar(&debugFilters,
daemonCommand.Flags().StringSliceVar(&debugFiltersArg,
"debug-filter", []string{},
i18n.Tr("Display only the provided gRPC calls"))
daemonCommand.Flags().IntVar(&maxGRPCRecvMsgSize,
"max-grpc-recv-message-size", 16*1024*1024,
i18n.Tr("Sets the maximum message size in bytes the daemon can receive"))
return daemonCommand
}

func runDaemonCommand(srv rpc.ArduinoCoreServiceServer, daemonPort string) {
func runDaemonCommand(srv rpc.ArduinoCoreServiceServer, daemonPort, debugFile string, debug, daemonize bool, debugFiltersArg []string, maxGRPCRecvMsgSize int) {
logrus.Info("Executing `arduino-cli daemon`")

gRPCOptions := []grpc.ServerOption{}
Expand All @@ -113,11 +119,13 @@ func runDaemonCommand(srv rpc.ArduinoCoreServiceServer, daemonPort string) {
debugStdOut = out
}
}
debugFilters = debugFiltersArg
gRPCOptions = append(gRPCOptions,
grpc.UnaryInterceptor(unaryLoggerInterceptor),
grpc.StreamInterceptor(streamLoggerInterceptor),
)
}
gRPCOptions = append(gRPCOptions, grpc.MaxRecvMsgSize(maxGRPCRecvMsgSize))
s := grpc.NewServer(gRPCOptions...)

// register the commands service
Expand Down
1 change: 1 addition & 0 deletions internal/cli/daemon/interceptors.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

var debugStdOut io.Writer
var debugSeq uint32
var debugFilters []string

func log(isRequest bool, seq uint32, msg interface{}) {
prefix := fmt.Sprint(seq, " | ")
Expand Down

0 comments on commit 0540cee

Please sign in to comment.