{"record":{"id":"ab9faa486ca4a9b1","repo":"apache/beam","slug":"failed-to-connect-to-state-service-v","errorCode":null,"errorMessage":"failed to connect to state service %v","messagePattern":"failed to connect to state service (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/harness/statemgr.go","lineNumber":672,"sourceCode":"\nfunc (c *StateChannel) terminateStreamOnError(err error) {\n\tc.mu.Lock()\n\tif c.forceRecreate != nil {\n\t\tc.closedErr = err\n\t\tc.forceRecreate(c.id, err)\n\t\tc.forceRecreate = nil\n\t}\n\t// Cancelling context after forcing recreation to ensure closedErr is set.\n\tc.cancelFn()\n\tc.mu.Unlock()\n}\n\nfunc newStateChannel(ctx context.Context, port exec.Port) (*StateChannel, error) {\n\tctx, cancelFn := context.WithCancel(ctx)\n\tcc, err := dial(ctx, port.URL, \"state\", 15*time.Second)\n\tif err != nil {\n\t\tcancelFn()\n\t\treturn nil, errors.Wrapf(err, \"failed to connect to state service %v\", port.URL)\n\t}\n\tclient, err := fnpb.NewBeamFnStateClient(cc).State(ctx)\n\tif err != nil {\n\t\tcc.Close()\n\t\tcancelFn()\n\t\treturn nil, errors.Wrapf(err, \"failed to create state client %v\", port.URL)\n\t}\n\treturn makeStateChannel(ctx, port.URL, client, func() {\n\t\tcc.Close()\n\t\tcancelFn()\n\t}), nil\n}\n\nfunc makeStateChannel(ctx context.Context, id string, client stateClient, cancelFn context.CancelFunc) *StateChannel {\n\tret := &StateChannel{\n\t\tid:        id,\n\t\tclient:    client,\n\t\trequests:  make(chan *fnpb.StateRequest, 10),","sourceCodeStart":654,"sourceCodeEnd":690,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/harness/statemgr.go#L654-L690","documentation":"newStateChannel dials the Beam Fn State gRPC service at the port URL (15s timeout). If the dial fails, it wraps the error with the state service URL. This is a connectivity failure between the SDK harness and the runner's state service (or a missing/incorrect state ApiServiceDescriptor).","triggerScenarios":"Calling Open on the state manager when the runner-provided state gRPC endpoint is unreachable, TLS misconfigured, the runner died, or in direct mode where no state service exists and a test executor sets up its own endpoints.","commonSituations":"Network partitions between harness worker and runner, wrong endpoint from runner config, firewall/proxy blocking gRPC, runner OOM/crash mid-bundle, using state APIs on a runner without state service support.","solutions":["Verify network connectivity from the worker to the state service endpoint URL and that no proxy/firewall blocks gRPC.","Confirm the runner is healthy and still serving the state port; check runner logs for crashes.","Check TLS/certificate configuration for the gRPC endpoint.","Retry the pipeline; if reproducible on DirectRunner, file a Beam issue with the full wrapped error."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"conn, err := net.DialTimeout(\"tcp\", host, 5*time.Second)\nif err != nil { return fmt.Errorf(\"state service %s unreachable: %w\", host, err) }\nconn.Close()","typeGuard":null,"tryCatchPattern":"ch, err := mgr.Open(ctx, port)\nif err != nil && strings.Contains(err.Error(), \"failed to connect to state service\") {\n    return retry.Do(func() error { _, err := mgr.Open(ctx, port); return err }, retry.Attempts(3))\n}\nreturn err","preventionTips":["Verify state endpoint reachability before running jobs","Keep runner and workers on the same network/VPC","Monitor runner health during long bundles"],"tags":["go","grpc","network","beam"],"backgroundTag":"connection-refused","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}