{"record":{"id":"deb1e0603515c581","repo":"hashicorp/nomad","slug":"failed-to-stream-events-w","errorCode":null,"errorMessage":"failed to stream events: %w","messagePattern":"failed to stream events: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/operator_debug.go","lineNumber":953,"sourceCode":"\n\t// Create the output file\n\tfh, err := os.Create(c.path(path, \"eventstream.json\"))\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer fh.Close()\n\n\t// Get handle to events endpoint\n\tevents := client.EventStream()\n\n\t// Start streaming events\n\teventCh, err := events.Stream(c.ctx, c.topics, c.index, c.queryOpts())\n\tif err != nil {\n\t\tif errors.Is(err, context.Canceled) {\n\t\t\tc.verboseOut(\"Event stream canceled: No events captured\")\n\t\t\treturn nil\n\t\t}\n\t\treturn fmt.Errorf(\"failed to stream events: %w\", err)\n\t}\n\n\teventCount := 0\n\terrCount := 0\n\theartbeatCount := 0\n\tchannelEventCount := 0\n\n\tvar mErrs *multierror.Error\n\n\tfor {\n\t\tselect {\n\t\tcase event := <-eventCh:\n\t\t\tchannelEventCount++\n\t\t\tif event.Err != nil {\n\t\t\t\terrCount++\n\t\t\t\tc.verboseOutf(\"error from event stream: index; %d err: %v\", event.Index, event.Err)\n\t\t\t\tmErrs = multierror.Append(mErrs, fmt.Errorf(\"error at index: %d, Err: %w\", event.Index, event.Err))\n\t\t\t\tbreak","sourceCodeStart":935,"sourceCodeEnd":971,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/operator_debug.go#L935-L971","documentation":"captureEventStream subscribes to the Consul agent's event stream via events.Stream with the command's topics, index and query options. If the initial streaming call returns an error other than context.Canceled, the capture cannot proceed and the underlying cause is wrapped with this message. A canceled context is treated as a clean shutdown, not an error.","triggerScenarios":"events.Stream fails while opening the blocking query to the local agent: agent unreachable/down, bad -http-addr, invalid query options (stale index, bad token), connection refused or reset, TLS misconfiguration to the agent.","commonSituations":"Consul agent stopped or restarted mid-debug capture; wrong HTTP address/port for the agent; ACL token lacking event read permissions; capture interrupted with Ctrl-C then races a connection error (context.Canceled path instead).","solutions":["Confirm the Consul agent is running and its HTTP address is correct (curl http://127.0.0.1:8500/v1/agent/health)","Check the wrapped cause (%w) in the error text — it names the actual transport/HTTP failure","Verify the ACL token used has permission to read the requested event topics","Re-run the capture; transient agent restarts resolve once the agent is back"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"resp, err := http.Get(consulAddr + \"/v1/agent/health\")\nif err != nil || resp.StatusCode != 200 {\n\treturn fmt.Errorf(\"consul agent not reachable at %s\", consulAddr)\n}","typeGuard":null,"tryCatchPattern":"events, err := events.Stream(ctx, topics, index, opts)\nif err != nil {\n\tif errors.Is(err, context.Canceled) {\n\t\treturn nil // clean shutdown\n\t}\n\treturn fmt.Errorf(\"failed to stream events: %w\", err)\n}","preventionTips":["Confirm the agent is up and -http-addr is correct before starting a capture","Use an ACL token with event read permissions","Retry captures after transient agent restarts"],"tags":["network","streaming","consul-api"],"backgroundTag":"event-stream-failed","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}