Skip to content

Fail over to an mn= mirror node when a stream host will not connect - #35

Merged
gridoe merged 3 commits into
gridoe:mainfrom
mjaverto:mn-failover
Nov 17, 2026
Merged

gridoe merged 3 commits into
gridoe:mainfrom
mjaverto:mn-failover

Conversation

@mjaverto

@mjaverto mjaverto commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What

When YouTube assigns a stream node this machine cannot reach, playback stalls: every track costs a guest probe timeout and a 10-minute guest cooldown, then about 30 s of mpv Timeout was reached. The URLs YouTube returns already name working alternatives in mn=. This change uses them.

Closes #36

Change

  • refryt-resolve: mn_mirrors and mirror_url rebuild a googlevideo URL using another node from mn=. The path, signed query, and rrN prefix stay unchanged. mvi is the rrN index, not a position in mn=, so mirrors include every entry except the current node.
  • probe_first_byte replaces the guest probe and probes yt-dlp URLs before direct mpv handoff. Transport failures try mirrors; HTTP statuses, including 403/410 expiry, remain errors rather than triggering probe failover. A working mirror avoids tripping the resolver chain breaker.
  • StreamProxy::fetch_range retries transport failures or missing response headers on mirrors and retains the node that answers. A mirror's 403/410 response uses the existing URL-refresh path.
  • Each proxy media request gets a 5 s send/response-header deadline, including mirror and refreshed-URL attempts. Body reads remain outside that deadline. Guest player requests keep their existing 15 s allowance; the shared client has no new connection cap.
  • mpv gets an optional, best-effort curl-connect-timeout=5, not a global network-timeout=5 read cap. Unsupported mpv versions remain usable.
  • A play-generation check after the direct-stream probe prevents a superseded cached play from replacing the selected track.

Review corrections

Review removed the global mpv read cap and shared 2 s connection cap, which could reject healthy slow streams and guest connections. It also added the post-probe generation check. Three final source reviews found no confirmed actionable regression.

Testing

  • Local gates passed on macOS with Rust stable 1.100: formatting, workspace and native-feature Clippy with warnings denied, workspace and native-feature tests, and Windows GNU cross-target Clippy. These are local results, not a Windows runtime test or a remote CI pass.
  • Permanent tests cover URL rewriting, signed-query preservation, transport-error and rejected-mirror recovery, sticky mirror selection, exact range bytes, primary 403/410 handling, and mirror 403/410 refresh.
  • Production player settings, the real proxy, and headless mpv reproduced the slow-stream failure before correction. After correction, a 1 MiB range streamed over 8.127 s, playback advanced 8.039 s, and no timeout or error occurred.
  • A held cached-play probe reproduced obsolete-track loading before correction. After correction, mpv kept the selected track and emitted no stale Playing event.
  • A local TLS comparison confirmed that the removed 2 s shared connection cap rejected a connection that succeeded after about 3 s without that cap. A curl-backed mpv comparison confirmed its separate connection-timeout setting.
  • A permanent proxy regression keeps the primary TCP connection open without response headers. The production deadline triggers mirror recovery and returns the requested bytes. It passed with both resolver feature sets.
  • Original author-reported testing: during a live unreachable-node incident, resolve-spike switched to a sn-8xgp1vo mirror in 5.6 s. The built macOS app then played from that mirror. This was not rerun during review.
  • Upstream GitHub Actions requires maintainer approval for this forked PR. Linux CI for this PR has not run; no remote CI pass is claimed.

@mjaverto
mjaverto marked this pull request as ready for review November 16, 2026 18:33
@gridoe
gridoe merged commit c765dac into gridoe:main Nov 17, 2026
3 checks passed
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.

Playback hangs when YouTube assigns a stream node this machine cannot reach

2 participants