@@ -34,16 +34,14 @@ import (
3434 "google.golang.org/grpc"
3535)
3636
37- var (
38- daemonize bool
39- debug bool
40- debugFile string
41- debugFilters []string
42- )
43-
4437// NewCommand created a new `daemon` command
4538func NewCommand (srv rpc.ArduinoCoreServiceServer , settings * rpc.Configuration ) * cobra.Command {
39+ var daemonize bool
40+ var debug bool
41+ var debugFile string
42+ var debugFiltersArg []string
4643 var daemonPort string
44+ var maxGRPCRecvMsgSize int
4745 daemonCommand := & cobra.Command {
4846 Use : "daemon" ,
4947 Short : i18n .Tr ("Run the Arduino CLI as a gRPC daemon." ),
@@ -63,9 +61,14 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer, settings *rpc.Configuration) *
6361 panic ("Failed to set default value for directories.builtin.libraries: " + err .Error ())
6462 }
6563 }
64+
65+ // Validate the maxGRPCRecvMsgSize flag
66+ if maxGRPCRecvMsgSize < 1024 {
67+ feedback .Fatal (i18n .Tr ("%s must be >= 1024" , "--max-grpc-recv-message-size" ), feedback .ErrBadArgument )
68+ }
6669 },
6770 Run : func (cmd * cobra.Command , args []string ) {
68- runDaemonCommand (srv , daemonPort )
71+ runDaemonCommand (srv , daemonPort , debugFile , debug , daemonize , debugFiltersArg , maxGRPCRecvMsgSize )
6972 },
7073 }
7174 defaultDaemonPort := settings .GetDaemon ().GetPort ()
@@ -82,13 +85,16 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer, settings *rpc.Configuration) *
8285 daemonCommand .Flags ().StringVar (& debugFile ,
8386 "debug-file" , "" ,
8487 i18n .Tr ("Append debug logging to the specified file" ))
85- daemonCommand .Flags ().StringSliceVar (& debugFilters ,
88+ daemonCommand .Flags ().StringSliceVar (& debugFiltersArg ,
8689 "debug-filter" , []string {},
8790 i18n .Tr ("Display only the provided gRPC calls" ))
91+ daemonCommand .Flags ().IntVar (& maxGRPCRecvMsgSize ,
92+ "max-grpc-recv-message-size" , 16 * 1024 * 1024 ,
93+ i18n .Tr ("Sets the maximum message size in bytes the daemon can receive" ))
8894 return daemonCommand
8995}
9096
91- func runDaemonCommand (srv rpc.ArduinoCoreServiceServer , daemonPort string ) {
97+ func runDaemonCommand (srv rpc.ArduinoCoreServiceServer , daemonPort , debugFile string , debug , daemonize bool , debugFiltersArg [] string , maxGRPCRecvMsgSize int ) {
9298 logrus .Info ("Executing `arduino-cli daemon`" )
9399
94100 gRPCOptions := []grpc.ServerOption {}
@@ -113,11 +119,13 @@ func runDaemonCommand(srv rpc.ArduinoCoreServiceServer, daemonPort string) {
113119 debugStdOut = out
114120 }
115121 }
122+ debugFilters = debugFiltersArg
116123 gRPCOptions = append (gRPCOptions ,
117124 grpc .UnaryInterceptor (unaryLoggerInterceptor ),
118125 grpc .StreamInterceptor (streamLoggerInterceptor ),
119126 )
120127 }
128+ gRPCOptions = append (gRPCOptions , grpc .MaxRecvMsgSize (maxGRPCRecvMsgSize ))
121129 s := grpc .NewServer (gRPCOptions ... )
122130
123131 // register the commands service
0 commit comments