{"record":{"id":"5bb6eee6adf3eaee","repo":"thanos-io/thanos","slug":"expected-4-components-in-config-metadata-and-rece","errorCode":null,"errorMessage":"expected 4 components in config metadata, and received %d, meta: %s","messagePattern":"expected 4 components in config metadata, and received (.+?), meta: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/discovery/memcache/resolver.go","lineNumber":72,"sourceCode":"\t\treturn nil, err\n\t}\n\n\treturn config, err\n}\n\nfunc (s *memcachedAutoDiscovery) parseConfig(reader *bufio.Reader) (*clusterConfig, error) {\n\tclusterConfig := new(clusterConfig)\n\n\tconfigMeta, err := reader.ReadString('\\n')\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to read config metadata: %s\", err)\n\t}\n\tconfigMeta = strings.TrimSpace(configMeta)\n\n\t// First line should be \"CONFIG cluster 0 [length-of-payload-]\n\tconfigMetaComponents := strings.Split(configMeta, \" \")\n\tif len(configMetaComponents) != 4 {\n\t\treturn nil, fmt.Errorf(\"expected 4 components in config metadata, and received %d, meta: %s\", len(configMetaComponents), configMeta)\n\t}\n\n\tconfigSize, err := strconv.Atoi(configMetaComponents[3])\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to parse config size from metadata: %s, error: %s\", configMeta, err)\n\t}\n\n\tconfigVersion, err := reader.ReadString('\\n')\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to find config version: %s\", err)\n\t}\n\tclusterConfig.version, err = strconv.Atoi(strings.TrimSpace(configVersion))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to parser config version: %s\", err)\n\t}\n\n\tnodes, err := reader.ReadString('\\n')\n\tif err != nil {","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/discovery/memcache/resolver.go#L54-L90","documentation":"After reading the first line of the memcached cluster CONFIG response, parseConfig splits it on spaces and expects exactly 4 components ('CONFIG cluster 0 <size>'). If the metadata line has a different number of space-separated tokens, the response does not conform to the protocol and this error is returned with the offending line embedded.","triggerScenarios":"The server's first response line is not 'CONFIG cluster 0 <len>' — e.g. an ERROR/CLIENT_ERROR reply from a non-cluster memcached, a truncated/corrupt response, or extra/missing tokens from a protocol-incompatible endpoint.","commonSituations":"Connecting to plain memcached (returns 'ERROR' to 'config get'), ElastiCache in non-cluster (replica) mode, or a custom/mock server emitting malformed metadata.","solutions":["Confirm the endpoint is a cluster-mode ElastiCache / memcached cluster answering 'CONFIG cluster ...'.","Inspect the raw first line (included in the error message) to identify the unexpected response.","Remove proxies or middlewares that alter the protocol response.","Fix test mocks to emit exactly 'CONFIG cluster 0 <len>\\r\\n'."],"exampleFix":"// before\n// server replies: \"ERROR unsupported command\" -> 2 components\n// after: validate endpoint mode first\nif !isClusterModeEndpoint(addr) {\n    return nil, errors.New(\"memcached auto-discovery requires a cluster-mode endpoint\")\n}","handlingStrategy":"validation","validationCode":"func looksLikeConfigMeta(line string) bool {\n    parts := strings.Fields(line)\n    return len(parts) == 4 && parts[0] == \"CONFIG\" && parts[1] == \"cluster\"\n}","typeGuard":null,"tryCatchPattern":"cfg, err := discovery.parseConfig(reader)\nif err != nil && strings.Contains(err.Error(), \"expected 4 components\") {\n    return nil, fmt.Errorf(\"endpoint %s is not answering the cluster CONFIG protocol: %w\", addr, err)\n}","preventionTips":["Confirm cluster-mode (ElastiCache 'cluster enabled') before enabling auto-discovery.","Probe the endpoint with a manual 'config get cluster\\r\\n' before wiring discovery.","Keep mock servers in tests byte-exact with the real protocol.","Route around proxies that rewrite plain-text memcached responses."],"tags":["memcached","protocol","validation","elasticache"],"backgroundTag":"unexpected-response-shape","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}