AlexxIT/go2rtc · error

exec: timeout

Error message

exec: timeout

What it means

When exec runs an RTSP-mode source ({output} in URL), handleRTSP waits for the spawned app to actually produce data, arming a timeout timer. If no data arrives from the process within the timeout window, the library kills the attempt and returns "exec: timeout" instead of serving a dead stream.

Solutions

  1. Run the command manually with the same arguments to see why it produces no output
  2. Fix the underlying source (reachable camera URL, correct credentials, correct flags)
  3. Increase the exec timeout query parameter (e.g. add ?timeout=...) if startup is legitimately slow
  4. Add flags to make the tool fail fast instead of hanging (e.g. ffmpeg -rw_timeout)

Example fix

// before
streams:
  cam: exec:ffmpeg -rtsp_transport tcp -i rtsp://cam/stream {output}
// after
streams:
  cam: exec:ffmpeg -rw_timeout 10000000 -rtsp_transport tcp -i rtsp://cam/stream {output}
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-check: run the command manually with a short timeout to confirm it emits data
ctx, cancel := context.WithTimeout(ctx, 15*time.Second); defer cancel()
out, err := exec.CommandContext(ctx, bin, args...).Output()

Try / catch

if _, err := tryOpen(src); err != nil && err.Error() == "exec: timeout" { log.Warn("app produced no data in time; check source availability") }

Prevention

When it happens

Trigger: The external command starts but produces no media data before the timeout expires: the binary hangs, waits for stdin interactively, blocks on a network source, or takes too long to output its first frames.

Common situations: ffmpeg/other binary stuck connecting to an unreachable camera URL; binary prompting for input; very slow source startup exceeding the timeout; wrong arguments causing the process to idle.

Understand the failure class

Background: Request timed out: what client-side request timeouts mean across libraries (Request timed out, TIMED_OUT, APITimeoutError) — this error's family across 39 libraries.

Related errors


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

Appendix: source

Thrown at internal/exec/exec.go:203

	}()

	log.Debug().Strs("args", cmd.Args).Msg("[exec] run rtsp")

	ts := time.Now()

	if err := cmd.Start(); err != nil {
		log.Error().Err(err).Str("source", source).Msg("[exec]")
		return nil, err
	}

	timer := time.NewTimer(timeout)
	defer timer.Stop()

	select {
	case <-timer.C:
		// haven't received data from app in timeout
		log.Error().Str("source", source).Msg("[exec] timeout")
		return nil, errors.New("exec: timeout")
	case <-cmd.Done():
		// app fail before we receive any data
		return nil, fmt.Errorf("exec/rtsp\n%s", cmd.Stderr)
	case prod := <-waiter:
		// app started successfully
		log.Debug().Stringer("launch", time.Since(ts)).Msg("[exec] run rtsp")
		setRemoteInfo(prod, source, cmd.Args)
		prod.OnClose = cmd.Close
		return prod, nil
	}
}

// internal

var (
	log       zerolog.Logger
	waiters   = make(map[string]chan *pkg.Conn)
	waitersMu sync.Mutex

View on GitHub (pinned to c245815e75)