Skip to content

feat(desktop): auto-stop server egress when host publish drops#23

Merged
ralyodio merged 1 commit into
masterfrom
feat/auto-stop-egress-on-host-drop
Jun 22, 2026
Merged

feat(desktop): auto-stop server egress when host publish drops#23
ralyodio merged 1 commit into
masterfrom
feat/auto-stop-egress-on-host-drop

Conversation

@ralyodio

Copy link
Copy Markdown
Contributor

Problem

When the host's WebRTC publish drops (flaky network / dead secondary NIC — the recurring dtls timeout ~20–90s into a stream), the room-composite egress was left orphaned: LiveKit keeps compositing the now-empty room, burning SFU CPU and pushing dead/frozen frames to every platform ("YouTube isn't getting any data") until the dead publisher finally times out server-side minutes later. On the 4-vCPU box that orphan also re-thrashed CPU and broke subsequent Go Lives.

Fix

New useAutoStopServerStream(isHosting, isServerStreaming, stopServerStream) hook stops the tracked egress on the hosting true -> false transition. The renderer stays alive during a media drop, so it can issue the stop promptly — well before the server-side participant timeout.

  • Fires only on the transition (not on mount, not while hosting stays up).
  • A user-initiated "stop server stream" clears the egress first (isServerStreaming -> false), so it never double-stops.
  • Paired with the start route already stopping pre-existing egress (feat(egress): stop existing room egress before starting a new one #22), a fully-crashed host is also cleaned up on the next Go Live. (No LiveKit webhook infra exists, so this client + next-start combination is the coverage without standing up a reaper.)

Test

Extracted the logic into a unit-testable hook (CapturePreview is too heavy to render in tests). 4 cases: stops on host-drop while streaming; no-op when not streaming; no fire on mount; no fire while hosting stays up. 4/4 pass; full monorepo lint passes.

Ships in the Electron app (desktop release), not Railway.

🤖 Generated with Claude Code

When the host's WebRTC publish drops (flaky network / dead secondary NIC),
the room-composite egress was left orphaned: LiveKit keeps compositing the
now-empty room, burning SFU CPU and pushing dead/frozen frames to every
platform until the dead publisher finally times out server-side minutes
later (which also re-thrashed the 4-vCPU box and broke subsequent streams).

New useAutoStopServerStream hook stops the tracked egress on the hosting
true->false transition. A user-initiated stop clears the egress first
(isServerStreaming -> false), so it never double-stops, and it never fires
before hosting has started. Paired with the start route already stopping
pre-existing egress (#22), a crashed host is also cleaned up on next Go Live.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@ralyodio ralyodio merged commit 157fba1 into master Jun 22, 2026
10 checks passed
@ralyodio ralyodio deleted the feat/auto-stop-egress-on-host-drop branch June 22, 2026 15:52
@github-actions

Copy link
Copy Markdown

vu1nz Security Review

0 finding(s) in PR #?

No security issues found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant