AlexxIT/go2rtc · error

add track from none state

Error message

add track from none state

What it means

Producer.AddTrack's state-machine guard: AddTrack was called while the producer is in stateNone, i.e. before its medias were probed. The producer refuses to attach a sender track because the connection is not yet in a state where tracks exist; like GetTrack, it requires at least stateMedias.

Solutions

  1. Probe the producer's medias first (Start / GetMedias) before AddTrack
  2. Sequence consumer setup after the producer is ready rather than in parallel
  3. Guard with state checks or waiters in custom pipelines
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/streams/producer.go:118 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of AlexxIT/go2rtc@c245815e75 (2026-09-07). Data as JSON: /api/errors/440be1c85703dbcc. Report an issue: GitHub.

Appendix: source

Thrown at internal/streams/producer.go:118

	if err != nil {
		return nil, err
	}

	p.receivers = append(p.receivers, track)

	if p.state == stateMedias {
		p.state = stateTracks
	}

	return track, nil
}

func (p *Producer) AddTrack(media *core.Media, codec *core.Codec, track *core.Receiver) error {
	p.mu.Lock()
	defer p.mu.Unlock()

	if p.state == stateNone {
		return errors.New("add track from none state")
	}

	if err := p.conn.(core.Consumer).AddTrack(media, codec, track); err != nil {
		return err
	}

	p.senders = append(p.senders, track)

	if p.state == stateMedias {
		p.state = stateTracks
	}

	return nil
}

func (p *Producer) MarshalJSON() ([]byte, error) {
	if conn := p.conn; conn != nil {
		return json.Marshal(conn)

View on GitHub (pinned to c245815e75)