Skip to content

Commit b7f8f0f

Browse files
committed
add env variable
1 parent ccc8d7b commit b7f8f0f

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

internal/envconfig/envconfig.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@ var (
126126
// enabled by setting the env variable
127127
// GRPC_EXPERIMENTAL_ENABLE_PRIORITY_LB_CHILD_POLICY_CACHE to true.
128128
EnablePriorityLBChildPolicyCache = boolFromEnv("GRPC_EXPERIMENTAL_ENABLE_PRIORITY_LB_CHILD_POLICY_CACHE", false)
129+
130+
// DefaultHeaderListSize indicates that default maximum header list size is
131+
// restricted to 8KB. This is disabled by default, but can be enabled by
132+
// setting the env variable "GRPC_GO_EXPERIMENTAL_DEFAULT_HEADER_LIST_SIZE"
133+
// to "true". When disabled, the default maximum header list size of 16MB is
134+
// used.
135+
//
136+
// When enabled RPCs with a total size of headers exceeding 8KB will fail
137+
// unless explicitly configured otherwise by the user.
138+
//
139+
// TODO: After a release, we will enable the env var by default.
140+
DefaultHeaderListSize = boolFromEnv("GRPC_GO_EXPERIMENTAL_DEFAULT_HEADER_LIST_SIZE", false)
129141
)
130142

131143
func boolFromEnv(envVar string, def bool) bool {

internal/transport/http2_client.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
"google.golang.org/grpc/internal"
4040
"google.golang.org/grpc/internal/channelz"
4141
icredentials "google.golang.org/grpc/internal/credentials"
42+
"google.golang.org/grpc/internal/envconfig"
4243
"google.golang.org/grpc/internal/grpclog"
4344
"google.golang.org/grpc/internal/grpcsync"
4445
"google.golang.org/grpc/internal/grpcutil"
@@ -317,6 +318,9 @@ func NewHTTP2Client(connectCtx, ctx context.Context, addr resolver.Address, opts
317318
writeBufSize := opts.WriteBufferSize
318319
readBufSize := opts.ReadBufferSize
319320
maxHeaderListSize := defaultClientMaxHeaderListSize
321+
if envconfig.DefaultHeaderListSize {
322+
maxHeaderListSize = upcomingDefaultHeaderListSize
323+
}
320324
if opts.MaxHeaderListSize != nil {
321325
maxHeaderListSize = *opts.MaxHeaderListSize
322326
}
@@ -877,7 +881,7 @@ func (t *http2Client) NewStream(ctx context.Context, callHdr *CallHdr, handler s
877881
return false
878882
}
879883
}
880-
if sz > int64(upcomingDefaultHeaderListSize) {
884+
if !envconfig.DefaultHeaderListSize && sz > int64(upcomingDefaultHeaderListSize) {
881885
t.logger.Warningf("Header list size to send (%d bytes) is larger than the upcoming default limit (%d bytes). In a future release, this will be restricted to %d bytes.", sz, upcomingDefaultHeaderListSize, upcomingDefaultHeaderListSize)
882886
}
883887
return true

internal/transport/http2_server.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"google.golang.org/protobuf/proto"
3939

4040
"google.golang.org/grpc/internal"
41+
"google.golang.org/grpc/internal/envconfig"
4142
"google.golang.org/grpc/internal/grpclog"
4243
"google.golang.org/grpc/internal/grpcutil"
4344
"google.golang.org/grpc/internal/pretty"
@@ -166,6 +167,9 @@ func NewServerTransport(conn net.Conn, config *ServerConfig) (_ ServerTransport,
166167
writeBufSize := config.WriteBufferSize
167168
readBufSize := config.ReadBufferSize
168169
maxHeaderListSize := defaultServerMaxHeaderListSize
170+
if envconfig.DefaultHeaderListSize {
171+
maxHeaderListSize = upcomingDefaultHeaderListSize
172+
}
169173
if config.MaxHeaderListSize != nil {
170174
maxHeaderListSize = *config.MaxHeaderListSize
171175
}
@@ -948,7 +952,7 @@ func (t *http2Server) checkForHeaderListSize(hf []hpack.HeaderField) bool {
948952
return false
949953
}
950954
}
951-
if sz > int64(upcomingDefaultHeaderListSize) {
955+
if !envconfig.DefaultHeaderListSize && sz > int64(upcomingDefaultHeaderListSize) {
952956
t.logger.Warningf("Header list size to send (%d bytes) is larger than the upcoming default limit (%d bytes). In a future release, this will be restricted to %d bytes.", sz, upcomingDefaultHeaderListSize, upcomingDefaultHeaderListSize)
953957
}
954958
return true

0 commit comments

Comments
 (0)