{"record":{"id":"16b3f2284bbb440e","repo":"AlexxIT/go2rtc","slug":"exec-timeout","errorCode":null,"errorMessage":"exec: timeout","messagePattern":"exec: timeout","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/exec/exec.go","lineNumber":203,"sourceCode":"\t}()\n\n\tlog.Debug().Strs(\"args\", cmd.Args).Msg(\"[exec] run rtsp\")\n\n\tts := time.Now()\n\n\tif err := cmd.Start(); err != nil {\n\t\tlog.Error().Err(err).Str(\"source\", source).Msg(\"[exec]\")\n\t\treturn nil, err\n\t}\n\n\ttimer := time.NewTimer(timeout)\n\tdefer timer.Stop()\n\n\tselect {\n\tcase <-timer.C:\n\t\t// haven't received data from app in timeout\n\t\tlog.Error().Str(\"source\", source).Msg(\"[exec] timeout\")\n\t\treturn nil, errors.New(\"exec: timeout\")\n\tcase <-cmd.Done():\n\t\t// app fail before we receive any data\n\t\treturn nil, fmt.Errorf(\"exec/rtsp\\n%s\", cmd.Stderr)\n\tcase prod := <-waiter:\n\t\t// app started successfully\n\t\tlog.Debug().Stringer(\"launch\", time.Since(ts)).Msg(\"[exec] run rtsp\")\n\t\tsetRemoteInfo(prod, source, cmd.Args)\n\t\tprod.OnClose = cmd.Close\n\t\treturn prod, nil\n\t}\n}\n\n// internal\n\nvar (\n\tlog       zerolog.Logger\n\twaiters   = make(map[string]chan *pkg.Conn)\n\twaitersMu sync.Mutex","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/internal/exec/exec.go#L185-L221","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run the command manually with the same arguments to see why it produces no output","Fix the underlying source (reachable camera URL, correct credentials, correct flags)","Increase the exec timeout query parameter (e.g. add ?timeout=...) if startup is legitimately slow","Add flags to make the tool fail fast instead of hanging (e.g. ffmpeg -rw_timeout)"],"exampleFix":"// before\nstreams:\n  cam: exec:ffmpeg -rtsp_transport tcp -i rtsp://cam/stream {output}\n// after\nstreams:\n  cam: exec:ffmpeg -rw_timeout 10000000 -rtsp_transport tcp -i rtsp://cam/stream {output}","handlingStrategy":"try-catch","validationCode":"// pre-check: run the command manually with a short timeout to confirm it emits data\nctx, cancel := context.WithTimeout(ctx, 15*time.Second); defer cancel()\nout, err := exec.CommandContext(ctx, bin, args...).Output()","typeGuard":null,"tryCatchPattern":"if _, err := tryOpen(src); err != nil && err.Error() == \"exec: timeout\" { log.Warn(\"app produced no data in time; check source availability\") }","preventionTips":["Add fail-fast flags to the spawned tool (ffmpeg -rw_timeout, -timeout)","Test exec commands interactively before wiring them as streams","Increase the timeout only after confirming the source is genuinely slow, not hung"],"tags":["timeout","exec","rtsp","process"],"backgroundTag":"request-timeout","analyzedSha":"c245815e75e2a5fd60b4290f12bfc04e55a984d3","analyzedAt":"2026-09-07T11:47:02.965Z","contentChangedAt":"2026-09-07T11:47:02.965Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}