Skip to content

fix(stream): apply ping_timeout to the ENet control peer - #6136

Open
Bectly wants to merge 1 commit into
SunshineStream:masterfrom
Bectly:fix/enet-control-peer-timeout
Open

Bectly wants to merge 1 commit into
SunshineStream:masterfrom
Bectly:fix/enet-control-peer-timeout

Conversation

@Bectly

@Bectly Bectly commented Nov 19, 2026

Copy link
Copy Markdown

Description

The control stream peer never gets enet_peer_timeout(), so it keeps ENet's defaults (ENET_PEER_TIMEOUT_MINIMUM = 5000 ms). On links with short outages (e.g. a client on a cellular hotspot) the host disconnects the client after ~5 s, even when ping_timeout is raised. The client then logs Control stream received unexpected disconnect event / Connection terminated: -1.

This sets the control peer's timeout to ping_timeout when the client connects, so the configured value actually governs how long a session survives a network outage.

Screenshot

Issues Fixed or Closed

Roadmap Issues

Testing

Manual validation on a Linux host (Fedora 45, NVIDIA, KMS capture + NVENC, build of v2026.914.233613 with this patch) and Moonlight-qt 6.2.0 on Windows over Tailscale and an LTE hotspot, ping_timeout = 30000:

  • Without the patch: real 4–6 s cellular outages ended the session twice; the host logged CLIENT DISCONNECTED about 5 s after the outage started.
  • With the patch: all traffic to the client was dropped for 7.2 s with nftables. The session stayed up; the client dropped the frames sent during the outage, requested an IDR and continued (connection status returned to OK). Moonlight's own control timeout is 10 s, so outages shorter than that are now survivable.

No automated test was added: the behaviour depends on ENet retransmission timing over a real socket, which the existing unit tests do not exercise.

Type of Change

  • feat: New feature (non-breaking change which adds functionality)
  • fix: Bug fix (non-breaking change which fixes an issue)
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semicolons, etc.)
  • refactor: Code change that neither fixes a bug nor adds a feature
  • perf: Code change that improves performance
  • test: Adding missing tests or correcting existing tests
  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Other changes that don't modify src or test files
  • revert: Reverts a previous commit
  • BREAKING CHANGE: Introduces a breaking change (can be combined with any type above)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas
  • Code docstring/documentation-blocks for new or existing methods/components have been added or updated
  • Tests have been added or updated for new or modified functionality, including regression tests for bug fixes

AI Usage

See our AI usage policy.

  • AI tools were used while preparing this PR

An AI assistant (Claude Code) traced the disconnects to the missing peer timeout, wrote the patch, built it and ran the outage test above.

🤖 Generated with Claude Code

The control stream peer never received enet_peer_timeout(), so it kept
ENet's defaults (5 s minimum). On links with short outages the host
disconnected the client after ~5 s regardless of ping_timeout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011uyno7VQowGYGzwwcHAfBT
@sonarqubecloud

Copy link
Copy Markdown

Copy link
Copy Markdown
Member

The 7.2-second recovery is encouraging. Before merging, could you compare patched and unpatched builds from the same base with identical controlled interruptions at both the default ping_timeout = 10000 and 30000? Please capture which side disconnects first and whether video and input resume after traffic returns.

The pinned ENet code treats 5 seconds as a retry-gated minimum, not a fixed outage cutoff. At Sunshine’s default, this patch sets both ENet bounds to 10 seconds (previously 5-second minimum and 30-second maximum) and changes the cap used in retransmission timing. Moonlight’s separate peer timeout also means the host’s 30-second setting does not guarantee 30 seconds of stream survival. This is a source check, not an independent live-stream test.

This branch has not been deployed

No deployments
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.

2 participants