Skip to content

Commit 0540cee

Browse files
authored
Increased gRPC message size limit to 16MB / added CLI flag to set the value (#2729)
* Removed globals in daemon command args parsing * Increased gRPC message size limit to 16MB / added CLI flag to set the value
1 parent ea09108 commit 0540cee

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

Diff for: internal/cli/daemon/daemon.go

+18-10
Original file line numberDiff line numberDiff line change
@@ -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
4538
func 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

Diff for: internal/cli/daemon/interceptors.go

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828

2929
var debugStdOut io.Writer
3030
var debugSeq uint32
31+
var debugFilters []string
3132

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

0 commit comments

Comments
 (0)