grafana/k6 · error

context is done before all

Error message

context is done before all '%s' events were processed

What it means

The wait-closure returned by System.Emit gives up: the context was cancelled/timed out while waiting for all subscribers of this event type to finish processing. Means a subscriber was too slow or the surrounding run was aborted mid-event.

Solutions

  1. Increase the timeout on the context passed to the wait function
  2. Make event subscribers faster or non-blocking
  3. Check whether the test run was aborted (ctrl-c, signal) which cancels the context by design
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/event/system.go:117 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/fc054f85a806f55f. Report an issue: GitHub.

Appendix: source

Thrown at internal/event/system.go:117

	}

	s.logger.WithFields(logrus.Fields{
		"subscribers": totalSubs,
		"event":       event.Type,
	}).Trace("Emitted event")

	return func(ctx context.Context) error {
		var doneCount int
		for {
			if doneCount == totalSubs {
				close(doneCh)
				return nil
			}
			select {
			case <-doneCh:
				doneCount++
			case <-ctx.Done():
				return fmt.Errorf("context is done before all '%s' events were processed", event.Type)
			}
		}
	}
}

// Unsubscribe closes the Event channel and removes the subscription with ID
// subID.
func (s *System) Unsubscribe(subID uint64) {
	s.subMx.Lock()
	defer s.subMx.Unlock()
	var seen bool
	for _, sub := range s.subscribers {
		if evtCh, ok := sub[subID]; ok {
			if !seen {
				close(evtCh)
			}
			delete(sub, subID)
			seen = true

View on GitHub (pinned to 01ffac6f24)