grafana/k6 · error

failed to create a new stream

Error message

failed to create a new stream: %w

What it means

Raised by the internal gRPC stream setup in beginStream when grpc-go's conn.NewStream fails to open a new stream over the underlying HTTP/2 connection. This wraps the underlying gRPC error and typically fires before any message is sent — e.g. when the connection is closed, the server refuses the stream, the named method is unknown, or a configured per-stream timeout (p.Timeout) expired before the stream headers could be sent.

Solutions

  1. Check the wrapped error for a gRPC status code to identify the cause (Unavailable, DeadlineExceeded, Unimplemented)
  2. Verify the connection is still open and the client was not closed before calling send() on the stream
  3. Increase the timeout value passed in the stream params if the deadline is being exceeded
  4. Retry stream creation with backoff for transient Unavailable errors
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at internal/js/modules/k6/grpc/stream.go:101 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@3fcf5388d7 (2026-08-18). Data as JSON: /api/errors/5a63ce31fbdbd29a. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/grpc/stream.go:101

		Method:                 s.method,
		MethodDescriptor:       s.methodDescriptor,
		DiscardResponseMessage: p.DiscardResponseMessage,
		TagsAndMeta:            &p.TagsAndMeta,
		Metadata:               p.Metadata,
	}

	ctx := s.vu.Context()
	var cancel context.CancelFunc

	if p.Timeout != time.Duration(0) {
		ctx, cancel = context.WithTimeout(ctx, p.Timeout)
	}

	s.timeoutCancel = cancel

	stream, err := s.client.conn.NewStream(ctx, *req)
	if err != nil {
		return fmt.Errorf("failed to create a new stream: %w", err)
	}
	s.stream = stream
	metrics.PushIfNotDone(s.vu.Context(), s.vu.State().Samples, metrics.Sample{
		TimeSeries: metrics.TimeSeries{
			Metric: s.instanceMetrics.Streams,
			Tags:   s.tagsAndMeta.Tags,
		},
		Time:     time.Now(),
		Metadata: s.tagsAndMeta.Metadata,
		Value:    1,
	})

	go s.loop()

	return nil
}

func (s *stream) loop() {

View on GitHub (pinned to 3fcf5388d7)