hashicorp/nomad · error

failed to stream events: %w

Error message

failed to stream events: %w

What it means

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.

Source

Thrown at command/operator_debug.go:953

	// Create the output file
	fh, err := os.Create(c.path(path, "eventstream.json"))
	if err != nil {
		return err
	}
	defer fh.Close()

	// Get handle to events endpoint
	events := client.EventStream()

	// Start streaming events
	eventCh, err := events.Stream(c.ctx, c.topics, c.index, c.queryOpts())
	if err != nil {
		if errors.Is(err, context.Canceled) {
			c.verboseOut("Event stream canceled: No events captured")
			return nil
		}
		return fmt.Errorf("failed to stream events: %w", err)
	}

	eventCount := 0
	errCount := 0
	heartbeatCount := 0
	channelEventCount := 0

	var mErrs *multierror.Error

	for {
		select {
		case event := <-eventCh:
			channelEventCount++
			if event.Err != nil {
				errCount++
				c.verboseOutf("error from event stream: index; %d err: %v", event.Index, event.Err)
				mErrs = multierror.Append(mErrs, fmt.Errorf("error at index: %d, Err: %w", event.Index, event.Err))
				break

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Confirm the Consul agent is running and its HTTP address is correct (curl http://127.0.0.1:8500/v1/agent/health)
  2. Check the wrapped cause (%w) in the error text — it names the actual transport/HTTP failure
  3. Verify the ACL token used has permission to read the requested event topics
  4. Re-run the capture; transient agent restarts resolve once the agent is back
Defensive patterns

Strategy: retry

Validate before calling

resp, err := http.Get(consulAddr + "/v1/agent/health")
if err != nil || resp.StatusCode != 200 {
	return fmt.Errorf("consul agent not reachable at %s", consulAddr)
}

Try / catch

events, err := events.Stream(ctx, topics, index, opts)
if err != nil {
	if errors.Is(err, context.Canceled) {
		return nil // clean shutdown
	}
	return fmt.Errorf("failed to stream events: %w", err)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/deb1e0603515c581. Report an issue: GitHub.