{"record":{"id":"53d02d12882bf002","repo":"apache/beam","slug":"unexpected-error-reading-varint-w","errorCode":null,"errorMessage":"unexpected error reading varint: %w","messagePattern":"unexpected error reading varint: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/exec/userstate.go","lineNumber":598,"sourceCode":"\tif err := enc.Encode(&fv, &buf); err != nil {\n\t\treturn err\n\t}\n\t_, err := w.Write(buf.Bytes())\n\treturn err\n}\n\n// decodeOrderedListEntry reads varint(sortKey) || coder_encoded(value) from r.\nfunc decodeOrderedListEntry(r io.Reader, c *coder.Coder) (state.OrderedListEntry, error) {\n\t// Read varint byte-by-byte.\n\tvar buf [10]byte // max varint size\n\tvar n int\n\tfor n = 0; n < len(buf); n++ {\n\t\t_, err := r.Read(buf[n : n+1])\n\t\tif err != nil {\n\t\t\tif n == 0 {\n\t\t\t\treturn state.OrderedListEntry{}, err\n\t\t\t}\n\t\t\treturn state.OrderedListEntry{}, fmt.Errorf(\"unexpected error reading varint: %w\", err)\n\t\t}\n\t\tif buf[n]&0x80 == 0 {\n\t\t\tn++\n\t\t\tbreak\n\t\t}\n\t}\n\tsortKey, consumed := protowire.ConsumeVarint(buf[:n])\n\tif consumed < 0 {\n\t\treturn state.OrderedListEntry{}, fmt.Errorf(\"invalid varint in ordered list entry\")\n\t}\n\n\tdec := MakeElementDecoder(coder.SkipW(c))\n\tfv, err := dec.Decode(r)\n\tif err != nil {\n\t\treturn state.OrderedListEntry{}, err\n\t}\n\treturn state.OrderedListEntry{SortKey: int64(sortKey), Value: fv.Elm}, nil\n}","sourceCodeStart":580,"sourceCodeEnd":616,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/exec/userstate.go#L580-L616","documentation":"decodeOrderedListEntry reads a varint sort key byte-by-byte from the state API stream. If a read fails midway (after some bytes were consumed), the partial varint can't be returned cleanly, so the byte-level error is wrapped with this message. It signals an unexpected mid-entry failure of the ordered-list state reader.","triggerScenarios":"Reading an ordered list state entry where the underlying Read call fails after the first byte — network drop to the state/harness service, stream closed mid-entry, or truncated state response.","commonSituations":"Dataflow/runner harness connection resets during state reads; state service timeouts; reading past the end of a malformed stream; transient gRPC/HTTP failures on the state API channel.","solutions":["Retry the state read — the first byte's error is returned directly (likely EOF), so a wrapped error means a mid-entry interruption worth retrying.","Check the state API connection stability between SDK harness and runner (timeouts, keepalives, proxies).","Inspect the wrapped inner error (%w) to identify the transport failure.","Reduce list state entry sizes / verify the state server didn't truncate the response."],"exampleFix":"// before: one-shot read without resilience\nentry, err := ReadOrderedListState(ctx, ...)\n// after: retry on transient mid-read failures\nentry, err := ReadOrderedListState(ctx, ...)\nif err != nil {\n    return retryWithBackoff(ctx, func() error { _, e := ReadOrderedListState(ctx, ...); return e })\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"entry, err := ReadOrderedListState(ctx, ...)\nif err != nil {\n    var retriable = isTransportError(err) // inspect wrapped %w error\n    if retriable { entry, err = retryWithBackoff(ctx, read) }\n}","preventionTips":["Inspect the wrapped inner error to classify transport vs data issues","Harden harness-to-runner state connections (keepalives, timeouts)","Retry state reads on transient mid-entry I/O failures"],"tags":["beam-go","state-api","io","varint"],"backgroundTag":"file-read-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}