{"record":{"id":"7a64fccf6ab3aa6c","repo":"thanos-io/thanos","slug":"could-not-parse-replica-header-7a64fc","errorCode":null,"errorMessage":"could not parse replica header","messagePattern":"could not parse replica header","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"pkg/receive/handler_otlp.go","lineNumber":101,"sourceCode":"\tfor _, ts := range metrics {\n\t\ttotalSamples += len(ts.Samples)\n\t}\n\n\tif !requestLimiter.AllowSeries(tenant, int64(len(metrics))) {\n\t\thttp.Error(w, \"too many timeseries\", http.StatusRequestEntityTooLarge)\n\t\treturn\n\t}\n\n\tif !requestLimiter.AllowSamples(tenant, int64(totalSamples)) {\n\t\thttp.Error(w, \"too many samples\", http.StatusRequestEntityTooLarge)\n\t\treturn\n\t}\n\n\trep := uint64(0)\n\t// If the header is empty, we assume the request is not yet replicated.\n\tif replicaRaw := r.Header.Get(h.options.ReplicaHeader); replicaRaw != \"\" {\n\t\tif rep, err = strconv.ParseUint(replicaRaw, 10, 64); err != nil {\n\t\t\thttp.Error(w, \"could not parse replica header\", http.StatusBadRequest)\n\t\t\treturn\n\t\t}\n\t}\n\n\t//TODO: (nicolastakashi) Handle metadata in the future.\n\twreq := tprompb.WriteRequest{\n\t\tTimeseries: metrics,\n\t}\n\n\t// Exit early if the request contained no data. We don't support metadata yet. We also cannot fail here, because\n\t// this would mean lack of forward compatibility for remote write proto.\n\tif len(wreq.Timeseries) == 0 {\n\t\t// TODO(yeya24): Handle remote write metadata.\n\t\tif len(wreq.Metadata) > 0 {\n\t\t\t// TODO(bwplotka): Do we need this error message?\n\t\t\tlevel.Debug(tLogger).Log(\"msg\", \"only metadata from client; metadata ingestion not supported; skipping\")\n\t\t\treturn\n\t\t}","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/receive/handler_otlp.go#L83-L119","documentation":"HTTP 400 returned when the replica header configured on the receive handler (h.options.ReplicaHeader, e.g. THANOS-REPLICA) is present but its value is not a valid unsigned 64-bit integer parseable by strconv.ParseUint. The replica number marks which receive node originally handled the request for deduplication of replicated writes.","triggerScenarios":"A client or upstream receive node sets the replica header to a non-numeric value (e.g. a hostname, empty-with-spaces value, or signed/oversized number).","commonSituations":"Misconfigured load balancer injecting the header with the node name instead of the replica index; hand-rolled forwarding scripts copying the wrong header; version mismatch where a peer sets a differently formatted header.","solutions":["Set the replica header value to a plain non-negative integer (e.g. \"0\", \"1\", \"2\").","Fix the proxy/router that injects the header so it forwards the numeric replica index, not the hostname.","Ensure the sending receive replica is configured with a matching numeric replica index in its hashring/replica config.","Remove the header entirely if the request is not replicated (empty header is treated as non-replicated)."],"exampleFix":"// before\nreq.Header.Set(\"THANOS-REPLICA\", \"receive-0.example.com\")\n// after\nreq.Header.Set(\"THANOS-REPLICA\", \"0\")","handlingStrategy":"validation","validationCode":"if v := req.Header.Get(\"THANOS-REPLICA\"); v != \"\" {\n    if _, err := strconv.ParseUint(v, 10, 64); err != nil {\n        req.Header.Del(\"THANOS-REPLICA\")\n    }\n}","typeGuard":"func validReplicaHeader(v string) bool { _, err := strconv.ParseUint(v, 10, 64); return err == nil }","tryCatchPattern":"if resp.StatusCode == 400 && strings.Contains(respBody, \"replica header\") { fixForwardingProxyHeader() }","preventionTips":["Only set the replica header from code that owns the numeric replica index","Strip the header at external ingress so clients can't forge it","Test replication paths after proxy changes"],"tags":["http","thanos","header","replication"],"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"}