{"record":{"id":"c9ef2fa85c575b1b","repo":"apache/beam","slug":"failed-to-sample-v","errorCode":null,"errorMessage":"Failed to sample: %v","messagePattern":"Failed to sample: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"sdks/go/pkg/beam/core/runtime/harness/sampler.go","lineNumber":46,"sourceCode":"}\n\nfunc newSampler(store *metrics.Store, elementProcessingTimeout time.Duration) *stateSampler {\n\treturn &stateSampler{sampler: metrics.NewSampler(store, elementProcessingTimeout), done: make(chan int)}\n}\n\nfunc (s *stateSampler) start(ctx context.Context, t time.Duration) error {\n\tticker := time.NewTicker(t)\n\tdefer ticker.Stop()\n\tfor {\n\t\tselect {\n\t\tcase <-s.done:\n\t\t\treturn nil\n\t\tcase <-ctx.Done():\n\t\t\treturn nil\n\t\tcase <-ticker.C:\n\t\t\terr := s.sampler.Sample(ctx, t)\n\t\t\tif err != nil {\n\t\t\t\treturn errors.Errorf(\"Failed to sample: %v\", err)\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunc (s *stateSampler) stop() {\n\tclose(s.done)\n}\n","sourceCodeStart":28,"sourceCodeEnd":55,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/harness/sampler.go#L28-L55","documentation":"The harness stateSampler goroutine periodically invokes s.sampler.Sample(ctx, t) on each ticker tick to sample worker state for progress/timeout reporting. If Sample returns an error, the goroutine returns errors.Errorf(\"Failed to sample: %v\", err). This is a secondary monitoring feature; the message surfaces the reason state sampling could not run, not a pipeline data-processing failure itself.","triggerScenarios":"The ticker fires and s.sampler.Sample(ctx, t) returns an error — typically because the underlying sampling mechanism (reading sampler state or the context) fails while the harness is running bundles.","commonSituations":"Sampling racing against harness shutdown (context cancelled between ctx.Done and Sample); sampler state invalidated during bundle/process teardown; rare runtime faults in the state sampler hook.","solutions":["Check the wrapped inner error from the message to find the real sampler failure cause.","If it appears only at shutdown, treat it as benign noise and ignore it.","If it recurs during steady state, report/upgrade — it usually indicates an SDK bug in sampler state handling.","Ensure the harness is not being killed/restarted mid-sample (stabilize the worker environment).","Reduce sampling frequency or disable sampling where the runner supports it in constrained environments."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := worker.Run(ctx, opts); err != nil {\n    if strings.Contains(err.Error(), \"Failed to sample\") && ctx.Err() != nil {\n        return nil // sampling raced with shutdown; benign\n    }\n    return err\n}","preventionTips":["Ignore this error when it coincides with harness shutdown/cancellation.","Keep worker processes stable (no mid-run kills) so sampling doesn't race teardown.","If recurring in steady state, upgrade the SDK — usually an SDK-side sampler bug.","Cross-check the inner error text in the message for the actual root cause."],"tags":["beam-go","runtime","monitoring","sampling"],"backgroundTag":"sampler-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"}