{"record":{"id":"0808c838db81713f","repo":"grafana/k6","slug":"the-protobuf-message-is-too-large-to-be-handled-by","errorCode":null,"errorMessage":"the protobuf message is too large to be handled by Snappy encoder; size: %d, limit: %d","messagePattern":"the protobuf message is too large to be handled by Snappy encoder; size: (.+?), limit: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/output/prometheusrw/remote/client.go","lineNumber":130,"sourceCode":"\t}()\n\n\t_, err = io.Copy(io.Discard, resp.Body)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\treturn validateResponseStatus(resp.StatusCode)\n}\n\nfunc newWriteRequestBody(series []*prompb.TimeSeries) ([]byte, error) {\n\tb, err := proto.Marshal(&prompb.WriteRequest{\n\t\tTimeseries: series,\n\t})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"encoding series as protobuf write request failed: %w\", err)\n\t}\n\tif snappy.MaxEncodedLen(len(b)) < 0 {\n\t\treturn nil, fmt.Errorf(\"the protobuf message is too large to be handled by Snappy encoder; \"+\n\t\t\t\"size: %d, limit: %d\", len(b), math.MaxUint32)\n\t}\n\treturn snappy.Encode(nil, b), nil\n}\n\nfunc validateResponseStatus(code int) error {\n\tif code >= http.StatusOK && code < 300 {\n\t\treturn nil\n\t}\n\n\treturn fmt.Errorf(\"got status code: %d instead expected a 2xx successful status code\", code)\n}\n","sourceCodeStart":112,"sourceCodeEnd":143,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/output/prometheusrw/remote/client.go#L112-L143","documentation":"The marshaled protobuf WriteRequest is so large that its Snappy-encoded length would overflow uint32, so the batch can never be sent as one remote-write request. The reported size exceeds the ~4GiB encoder limit.","triggerScenarios":"Thrown at internal/output/prometheusrw/remote/client.go:130 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Reduce the number of time series per batch (lower K6_PROMETHEUS_RW_MAX_BATCH_SIZE or the equivalent)","Reduce metric cardinality: fewer custom tags/labels in the script","Shorten the flush interval so batches are smaller"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}