grpc/grpc-go · warning
invalid header/message length config: %q, %v
Error message
invalid header/message length config: %q, %v
What it means
Returned by fillMethodLoggerWithConfigString when parseHeaderMessageLengthConfig fails on the suffix of a method or service entry (env_config.go:102-104). The suffix (e.g., '{h:256;m:512}') extracted from the entry must match one of the three recognized patterns: {h}, {h:N}, {m}, {m:N}, {h;m}, or {h:N;m:N}. The %q is the suffix string; %v is the parse error. This differs from error 276 in that it applies to method/service entries, not the global '*' rule, and uses a different error prefix ('invalid header/message length config').
Source
Thrown at internal/binarylog/env_config.go:104
// "*{h:256;m:256}"
if config[0] == '*' {
hdr, msg, err := parseHeaderMessageLengthConfig(config[1:])
if err != nil {
return fmt.Errorf("invalid config: %q, %v", config, err)
}
if err := l.setDefaultMethodLogger(&MethodLoggerConfig{Header: hdr, Message: msg}); err != nil {
return fmt.Errorf("invalid config: %v", err)
}
return nil
}
s, m, suffix, err := parseMethodConfigAndSuffix(config)
if err != nil {
return fmt.Errorf("invalid config: %q, %v", config, err)
}
hdr, msg, err := parseHeaderMessageLengthConfig(suffix)
if err != nil {
return fmt.Errorf("invalid header/message length config: %q, %v", suffix, err)
}
if m == "*" {
if err := l.setServiceMethodLogger(s, &MethodLoggerConfig{Header: hdr, Message: msg}); err != nil {
return fmt.Errorf("invalid config: %v", err)
}
} else {
if err := l.setMethodMethodLogger(s+"/"+m, &MethodLoggerConfig{Header: hdr, Message: msg}); err != nil {
return fmt.Errorf("invalid config: %v", err)
}
}
return nil
}
const (
// TODO: this const is only used by env_config now. But could be useful for
// other config. Move to binarylog.go if necessary.
maxUInt = ^uint64(0)
View on GitHub (pinned to 0c51461d27)
Solutions
- Use valid suffix formats: '{h:256}', '{m:512}', '{h:256;m:512}', '{h}', '{m}', or omit the suffix for full logging
- Ensure only 'h' (header) and 'm' (message) keys are used
- Ensure numeric values are decimal integers parseable by strconv.ParseUint
Example fix
# before (malformed length suffix on method entry)
export GRPC_BINARY_LOG_FILTER="Foo/Bar{h:abc}"
# after (valid numeric header length)
export GRPC_BINARY_LOG_FILTER="Foo/Bar{h:256}" Defensive patterns
Strategy: validation
Validate before calling
// Validate header/message length suffix on method/service entries
var lengthSuffixRe = regexp.MustCompile(`^\{(?:(?:h(?::\d+)?)?(?:;m(?::\d+)?)?|m(?::\d+)?)\}$`)
func validateLengthSuffix(entry string) error {
braceStart := strings.Index(entry, "{")
if braceStart < 0 {
return nil // no suffix, valid
}
suffix := entry[braceStart:]
if !lengthSuffixRe.MatchString(suffix) {
return fmt.Errorf("invalid length suffix %q; use {h:N}, {m:N}, {h:N;m:N}, {h}, or {m}", suffix)
}
return nil
} Prevention
- Use only 'h' (header) and 'm' (message) keys in length suffixes
- Ensure numeric values are decimal integers parseable by strconv.ParseUint
- Test the suffix format against the recognized patterns before deploying
When it happens
Trigger: A method or service entry in GRPC_BINARY_LOG_FILTER with a malformed length suffix, e.g., 'Foo/Bar{invalid}', 'Foo/Bar{h:abc}' (non-numeric), 'Foo/Bar{x:256}' (unknown key), or 'Foo/Bar{}'. The suffix must match headerConfigRegexp, messageConfigRegexp, or headerMessageConfigRegexp.
Common situations: Typos in the header/message length specification. Using unsupported keys (only 'h' and 'm' are valid). Non-numeric values where ParseUint expects decimal integers.
Related errors
- conflicting global rules found
- conflicting service rules for service %v found
- conflicting blacklist rules for method %v found
- conflicting method rules for method %v found
- invalid config: %q, %v
AI-assisted analysis of grpc/grpc-go@0c51461d27 (2026-08-11).
Data as JSON: /api/errors/868b77412146179a.
Report an issue: GitHub.