{"record":{"id":"80f53dd233690b26","repo":"thanos-io/thanos","slug":"failed-to-parse-config-size-from-metadata-s-err","errorCode":null,"errorMessage":"failed to parse config size from metadata: %s, error: %s","messagePattern":"failed to parse config size from metadata: (.+?), error: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/discovery/memcache/resolver.go","lineNumber":77,"sourceCode":"\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 {\n\t\treturn nil, fmt.Errorf(\"failed to read nodes: %s\", err)\n\t}\n\n\tif len(configVersion)+len(nodes) != configSize {\n\t\treturn nil, fmt.Errorf(\"expected %d in config payload, but got %d instead\", configSize, len(configVersion)+len(nodes))","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/discovery/memcache/resolver.go#L59-L95","documentation":"The 4th token of the CONFIG metadata line is the payload byte length and must be a decimal integer. parseConfig parses it with strconv.Atoi; if it is not a valid integer (empty or non-numeric), this error is returned showing the full metadata line and the strconv error. It indicates a malformed or corrupted CONFIG response header.","triggerScenarios":"The metadata line splits into 4 components but the last is non-numeric, e.g. 'CONFIG cluster 0 abc' or a mangled/interleaved response where the length token is corrupted.","commonSituations":"Corrupted TCP stream framing; a proxy injecting text into the response; custom servers writing the length in hex or with a suffix; hand-written malformed fixtures in tests.","solutions":["Fix the server/mock to emit a decimal byte length as the 4th token.","Check for stream corruption: verify TLS/plain-text expectations and remove transforming proxies.","Log and compare the metadata line against the spec 'CONFIG cluster 0 <len>'.","Update test fixtures to include a valid numeric size."],"exampleFix":"// before\n// response: \"CONFIG cluster 0 1f2e\" -> strconv.Atoi fails\n// after\nfmt.Fprintf(w, \"CONFIG cluster 0 %d\\r\\n\", len(payload))","handlingStrategy":"validation","validationCode":"func validConfigSize(meta string) error {\n    parts := strings.Fields(meta)\n    if len(parts) != 4 {\n        return fmt.Errorf(\"bad meta %q\", meta)\n    }\n    _, err := strconv.Atoi(parts[3])\n    return err\n}","typeGuard":null,"tryCatchPattern":"if err := validConfigSize(metaLine); err != nil {\n    return nil, fmt.Errorf(\"malformed CONFIG header from %s: %w\", addr, err)\n}","preventionTips":["Emit the payload length as a plain decimal integer in servers/mocks.","Verify no proxy modifies the response stream.","Match TLS/plain-text expectations to avoid byte corruption.","Unit-test parseConfig against spec-exact fixture responses."],"tags":["memcached","protocol","parsing","validation"],"backgroundTag":"invalid-argument-format","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"}